Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update code #279

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/XDAGJ_Message_Encoding_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Message Encoding
Xdagj network messages format.

## Types

### boolean
1 bit

### long
8 bytes

### int
4 bytes

### byte[]
First write the number of bytes using [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity), then write each byte.

### string
First write the number of bytes using [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity), then write each byte of the string.

## VLQ
Variable length quantity. This encoding allows for writing both large and small numbers in an efficient manner.
92 changes: 92 additions & 0 deletions docs/XDAGJ_Network_Protocol_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Network Protocol

Clients send messages to peers in order to interact with the blockchain. These can be
divided into general peer messages, and consensus methods used by validators for forging blocks.

Messages are written using the XDAGJ [XDAGJ_Message_Encoding](./XDAGJ_Message_Encoding_en.md) format.

Messages send the code byte first, then the parameters in order


## Standard Message Objects

### Peer

Message:
- ip (string)
- port (int)
- networkVersion (short)
- clientId (string)
- peerId (string)
- latestBlockNumber (long)
- capabilities size (int)
- capabilities[] (string[])

## P2P Messages

- [0x00, 0x0f] Reserved for p2p basics

### Disconnect

Code: 0x00

Inform a peer of disconnection. Reasons can include too many peers, invalid handshake, or other.

Message:
- reason (byte)

### Hello

Code: 0x01

Initiate a connection with a peer. No messages will be accepted until after this handshake is done.

Message:
- peer (Peer)
- timestamp (long)
- signature (byte[])

### World

Code: 0x02

Respond to a Hello message indicating successful connection.

Message:
- peer (Peer)
- timestamp (long)
- signature (byte[])

### Ping

Code: 0x03

Request a reply from the peer to ensure connection is still valid.

Message:
- timestamp (long)

### Pong

Code: 0x04

Respond to a Ping message.

Message:
- timestamp (long)

## Consensus Messages

- [0x10, 0x1f] Reserved for node

### BLOCKS_REQUEST(0x10)
### BLOCKS_REPLY(0x11)
### SUMS_REQUEST(0x12)
### SUMS_REPLY(0x13)
### BLOCKEXT_REQUEST(0x14)
### BLOCKEXT_REPLY(0x15)
### BLOCK_REQUEST(0x16)
### RECEIVE_BLOCK(0x17)
### NEW_BLOCK(0x18)
### SYNC_BLOCK(0x19)
### SYNCBLOCK_REQUEST(0x1A)
85 changes: 0 additions & 85 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<bcprov-jdk18on.version>1.76</bcprov-jdk18on.version>
<bcpkix-jdk18on.version>1.76</bcpkix-jdk18on.version>
<vertx-core.version>4.4.0</vertx-core.version>
<discovery.version>22.2.0</discovery.version>
<jsonrpc4j.version>1.6</jsonrpc4j.version>
<jaxws-ri.version>4.0.1</jaxws-ri.version>
<config.version>1.4.2</config.version>
Expand Down Expand Up @@ -804,90 +803,6 @@
<version>${json.version}</version>
</dependency>

<dependency>
<groupId>tech.pegasys.discovery</groupId>
<artifactId>discovery</artifactId>
<version>${discovery.version}</version>
<exclusions>
<exclusion>
<artifactId>log4j-api</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-core</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>netty-all</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>bcprov-jdk15on</artifactId>
<groupId>org.bouncycastle</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>logging-interceptor</artifactId>
<groupId>com.squareup.okhttp3</groupId>
</exclusion>
<exclusion>
<artifactId>okhttp</artifactId>
<groupId>com.squareup.okhttp3</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jffi</artifactId>
<groupId>com.github.jnr</groupId>
</exclusion>
<exclusion>
<artifactId>jnr-constants</artifactId>
<groupId>com.github.jnr</groupId>
</exclusion>
<exclusion>
<artifactId>jnr-ffi</artifactId>
<groupId>com.github.jnr</groupId>
</exclusion>
<exclusion>
<artifactId>vertx-core</artifactId>
<groupId>io.vertx</groupId>
</exclusion>
<exclusion>
<artifactId>bytes</artifactId>
<groupId>org.apache.tuweni</groupId>
</exclusion>
<exclusion>
<artifactId>units</artifactId>
<groupId>org.apache.tuweni</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>tuweni-bytes</artifactId>
<groupId>org.apache.tuweni</groupId>
</exclusion>
<exclusion>
<artifactId>tuweni-io</artifactId>
<groupId>org.apache.tuweni</groupId>
</exclusion>
<exclusion>
<artifactId>tuweni-units</artifactId>
<groupId>org.apache.tuweni</groupId>
</exclusion>
</exclusions>
</dependency>

<!-- https://mvnrepository.com/artifact/com.github.briandilley.jsonrpc4j/jsonrpc4j -->
<dependency>
<groupId>com.github.briandilley.jsonrpc4j</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/xdag/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import io.xdag.crypto.Aes;
import io.xdag.crypto.Bip32ECKeyPair;
import io.xdag.crypto.Keys;
import io.xdag.crypto.MnemonicUtils;
import io.xdag.utils.MnemonicUtils;
import io.xdag.crypto.Sign;
import io.xdag.utils.Numeric;
import io.xdag.utils.SimpleDecoder;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/xdag/cli/XdagCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import io.xdag.config.Config;
import io.xdag.config.Constants;
import io.xdag.crypto.Keys;
import io.xdag.crypto.MnemonicUtils;
import io.xdag.utils.MnemonicUtils;
import io.xdag.crypto.Sign;
import io.xdag.db.SnapshotStore;
import io.xdag.db.rocksdb.DatabaseName;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/xdag/core/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ public Block(BlockInfo blockInfo) {
this.info = blockInfo;
this.isSaved = true;
this.parsed = true;

}

/**
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/io/xdag/crypto/Base58.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,6 @@ public static boolean checkAddress(String input) {
return Arrays.equals(checksum, actualChecksum);
}

public static boolean checkBytes24(byte[] data) {
if (data.length != 24) return false;
byte[] data20 = Arrays.copyOfRange(data, 0, data.length - 4);
byte[] checksum = Arrays.copyOfRange(data, data.length - 4, data.length);
byte[] actualChecksum = Arrays.copyOfRange(Hash.hashTwice(data20), 0, 4);
return Arrays.equals(checksum, actualChecksum);
}


private static byte divmod(byte[] number, int firstDigit, int base, int divisor) {
// this is just long division which accounts for the base of the input digits
int remainder = 0;
Expand Down
118 changes: 0 additions & 118 deletions src/main/java/io/xdag/crypto/LinuxSecureRandom.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/io/xdag/net/message/MessageCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public enum MessageCode {

// =======================================
// [0x00, 0x2f] Reserved for p2p basics
// [0x00, 0x0f] Reserved for p2p basics
// =======================================

/**
Expand Down
Loading