https://github.com/dimchat/core-java
Decentralized Instant Messaging Protocol (Java)
https://github.com/dimchat/core-java
Last synced: 5 months ago
JSON representation
Decentralized Instant Messaging Protocol (Java)
- Host: GitHub
- URL: https://github.com/dimchat/core-java
- Owner: dimchat
- License: mit
- Created: 2019-04-24T08:08:50.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-12-16T21:21:41.000Z (6 months ago)
- Last Synced: 2025-12-16T21:38:18.480Z (6 months ago)
- Language: Java
- Size: 1.03 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Decentralized Instant Messaging Protocol (Java)
[](https://github.com/dimchat/core-java/blob/master/LICENSE)
[](https://github.com/dimchat/core-java/pulls)
[](https://github.com/dimchat/core-java/wiki)
[](https://github.com/dimchat/core-java/issues)
[](https://github.com/dimchat/core-java/archive/refs/heads/master.zip)
[](https://github.com/dimchat/core-java/tags)
[](https://mvnrepository.com/artifact/chat.dim/DIMP)
[](https://github.com/dimchat/core-java/watchers)
[](https://github.com/dimchat/core-java/forks)
[](https://github.com/dimchat/core-java/stargazers)
[](https://github.com/orgs/dimchat/followers)
## Dependencies
* Latest Versions
| Name | Version | Description |
|------|---------|-------------|
| [Cryptography](https://github.com/dimchat/mkm-java) | [](https://mvnrepository.com/artifact/chat.dim/Crypto) | Crypto Keys |
| [Ming Ke Ming (名可名)](https://github.com/dimchat/mkm-java) | [](https://mvnrepository.com/artifact/chat.dim/MingKeMing) | Decentralized User Identity Authentication |
| [Dao Ke Dao (道可道)](https://github.com/dimchat/dkd-java) | [](https://mvnrepository.com/artifact/chat.dim/DaoKeDao) | Universal Message Module |
* build.gradle
```javascript
allprojects {
repositories {
mavenLocal()
mavenCentral()
google()
}
}
dependencies {
// https://central.sonatype.com/artifact/chat.dim/DIMP
implementation group: 'chat.dim', name: 'DIMP', version: '2.0.0'
}
```
* pom.xml
```xml
chat.dim
DIMP
2.0.0
pom
```
## Examples
### Extends Command
* _Handshake Command Protocol_
0. (C-S) handshake start
1. (S-C) handshake again with new session
2. (C-S) handshake restart with new session
3. (S-C) handshake success
```java
public enum HandshakeState {
START, // C -> S, without session key(or session expired)
AGAIN, // S -> C, with new session key
RESTART, // C -> S, with new session key
SUCCESS, // S -> C, handshake accepted
}
/**
* Handshake command message
*
*
* data format: {
* type : i2s(0x88),
* sn : 123,
*
* command : "handshake", // command name
* title : "Hello world!", // "DIM?", "DIM!"
* session : "{SESSION_KEY}" // session key
* }
*
*/
public class HandshakeCommand extends BaseCommand {
public final static String HANDSHAKE = "handshake";
public HandshakeCommand(Map content) {
super(content);
}
public HandshakeCommand(String text, String session) {
super(HANDSHAKE);
// text message
assert text != null : "new handshake command error";
put("title", text);
// session key
if (session != null) {
put("session", session);
}
}
public String getTitle() {
return getString("title", null);
}
public String getSessionKey() {
return getString("session", null);
}
public HandshakeState getState() {
return checkState(getTitle(), getSessionKey());
}
private static HandshakeState checkState(String text, String session) {
assert text != null : "handshake title should not be empty";
if (text.equals("DIM!")/* || text.equals("OK!")*/) {
return HandshakeState.SUCCESS;
} else if (text.equals("DIM?")) {
return HandshakeState.AGAIN;
} else if (session == null) {
return HandshakeState.START;
} else {
return HandshakeState.RESTART;
}
}
//
// Factories
//
public static HandshakeCommand start() {
return new HandshakeCommand("Hello world!", null);
}
public static HandshakeCommand restart(String sessionKey) {
return new HandshakeCommand("Hello world!", sessionKey);
}
public static HandshakeCommand again(String sessionKey) {
return new HandshakeCommand("DIM?", sessionKey);
}
public static HandshakeCommand success(String sessionKey) {
return new HandshakeCommand("DIM!", sessionKey);
}
}
```
### Extends Content
```java
/**
* Application Customized message: {
* 'type' : i2s(0xA0),
* 'sn' : 123,
*
* 'app' : "{APP_ID}", // application (e.g.: "chat.dim.sechat")
* 'extra' : info // others
* }
*/
public class ApplicationContent extends BaseContent implements AppContent {
public ApplicationContent(Map content) {
super(content);
}
public ApplicationContent(String app) {
super(ContentType.APPLICATION);
put("app", app);
}
@Override
public String getApplication() {
return getString("app", "");
}
}
```
### Extends ID Address
* Examples in [Plugins](https://mvnrepository.com/artifact/chat.dim/Plugins)
----
Copyright © 2018-2025 Albert Moky
[](https://github.com/moky?tab=followers)