Skip to content

Commit

Permalink
Merge pull request #187 from nervosnetwork/upgrade-dep
Browse files Browse the repository at this point in the history
chore: add readme and upgrade molecule
  • Loading branch information
driftluo authored Sep 20, 2019
2 parents f8d63d4 + bd3514a commit ac641a0
Show file tree
Hide file tree
Showing 18 changed files with 772 additions and 154 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tokio-threadpool = "0.1"
flatbuffers = { version = "0.6.0", optional = true }
flatbuffers-verifier = { version = "0.2.0", optional = true }
multiaddr = { package = "parity-multiaddr", version = "0.4.0" }
molecule = { version = "0.2.5", optional = true }
molecule = { version = "0.3.1", optional = true }

# upnp
igd = "0.9"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FLATC := flatc
CFBC := cfbc
MOLC := moleculec
MOLC_VERSION := 0.2.5
MOLC_VERSION := 0.3.1

FBS_FILES := \
src/protocol_select/protocol_select.fbs \
Expand Down
2 changes: 1 addition & 1 deletion protocols/discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ log = "0.4"
rand = "0.6.1"
flatbuffers = { version = "0.6.0", optional = true }
flatbuffers-verifier = { version = "0.2.0", optional = true }
molecule = { version = "0.2.5", optional = true }
molecule = { version = "0.3.1", optional = true }

[dev-dependencies]
env_logger = "0.6"
Expand Down
34 changes: 33 additions & 1 deletion protocols/discovery/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# discovery
## Discovery
Node discovery (mainly same with bitcoin, for blockchain project)

### Discovery behavior

On the current NAT forwarding network environment, whether it is self-discovery or the discovery behavior
of the other party is not completely accurate, it is certain that the address received by
the user is not 100% available.

There are two actions in this protocol:

- When the connection is established, the requester(Client) will actively request the responder(Server) to
request the list of available addresses that the responder has stored. **WARNING**: This behavior is only
allowed once, otherwise it will be disconnected by the other peers.

- Each node periodically broadcasts hot address to its neighbor peers. The hot address refers to the listen
address of the neighbor peers that the node keeps communicating continuously, which means active connection.

### Message type

```
/// request for address list
GetNodes {
version: Uint32,
count: Uint32,
listen_port: PortOpt,
}
/// response address list
Nodes {
announce: Bool,
items: NodeVec,
}
```
2 changes: 1 addition & 1 deletion protocols/discovery/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl DiscoveryMessage {
#[cfg(feature = "molc")]
#[allow(clippy::cast_ptr_alignment)]
pub fn decode(data: &[u8]) -> Option<Self> {
let reader = protocol_mol::DiscoveryMessageReader::from_slice(data).ok()?;
let reader = protocol_mol::DiscoveryMessageReader::from_compatible_slice(data).ok()?;
match reader.payload().to_enum() {
protocol_mol::DiscoveryPayloadUnionReader::GetNodes(reader) => {
let le = reader.version().raw_data().as_ptr() as *const u32;
Expand Down
Loading

0 comments on commit ac641a0

Please sign in to comment.