- Latest Versions
Name | Version | Description |
---|---|---|
Cryptography | Crypto Keys | |
Ming Ke Ming (名可名) | Decentralized User Identity Authentication | |
Dao Ke Dao (道可道) | Universal Message Module |
- build.gradle
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
<dependencies>
<!-- https://mvnrepository.com/artifact/chat.dim/DIMP -->
<dependency>
<groupId>chat.dim</groupId>
<artifactId>DIMP</artifactId>
<version>2.0.0</version>
<type>pom</type>
</dependency>
</dependencies>
- Handshake Command Protocol
0. (C-S) handshake start
- (S-C) handshake again with new session
- (C-S) handshake restart with new session
- (S-C) handshake success
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
*
* <blockquote><pre>
* data format: {
* type : 0x88,
* sn : 123,
*
* command : "handshake", // command name
* title : "Hello world!", // "DIM?", "DIM!"
* session : "{SESSION_KEY}" // session key
* }
* </pre></blockquote>
*/
public class HandshakeCommand extends BaseCommand {
public final static String HANDSHAKE = "handshake";
public HandshakeCommand(Map<String, Object> 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);
}
}
/**
* 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<String, Object> content) {
super(content);
}
public ApplicationContent(String app) {
super(ContentType.APPLICATION);
put("app", app);
}
@Override
public String getApplication() {
return getString("app", "");
}
}
- Examples in Plugins