Commmunication module exposes three main abstraction:
...
Transport Layer abstracts the communication pipeline, allowing two nodes sending messages between each other.
Specification of how TransportLayer should work is defined in TransportLayerSpec.scala
TcpTransportLayer
when doing a round trip to remote peer
when when everything is fine
- should send and receive the message
when when response takes to long
- should fail with a timeout
when there is no response body
- should fail with a communication error
when peer is not listening
- should fail with peer unavailable error
when there was a peer-side error
- should fail with an internal communication error
when sending a message
- should deliver the message
- should not wait for a response
- should wait for message being delivered (pending)
when brodacasting a message
- should send the message to all peers
when shutting down
when when doing a round trip
- should not send the message
when when sending a message
- should not send the message
when when broadcasting a message
- should not send any messages
Transport Layer exposes following functions:
trait TransportLayer[F[_]] { def local: F[PeerNode] def roundTrip(peer: PeerNode, msg: Protocol, timeout: FiniteDuration): F[CommErr[Protocol]] def send(peer: PeerNode, msg: Protocol): F[Unit] def broadcast(peers: Seq[PeerNode], msg: Protocol): F[Unit] def receive(dispatch: Protocol => F[CommunicationResponse]): F[Unit] def disconnect(peer: PeerNode): F[Unit] def shutdown(msg: Protocol): F[Unit] }
- disconnect
Method disconnect should never be part of TransportLayer abstraction. It is TcpTransportLayer implementation detail. It will be removed from the abstraction (see CORE-835 for details).
- shutdown
Shutdown method gracefully shuts down the Transport Layer. After being called, no message can be send (via roundTrip, send, broadcast) nor received.
- roundTrip, send, broadcast
Methods roundTrip and send allow sending and receiving messages of type Protocol - object defined in routing.proto. Protocol message can be one of the following:
message Protocol { Header header = 1; oneof message { google.protobuf.Any upstream = 2; Ping ping = 3; Pong pong = 4; Lookup lookup = 5; LookupResponse lookup_response = 6; Disconnect disconnect = 7; } }
- Ping, Pong, Loookup, LookupResponse
Ping+Pong and Lookup+LookupResponse are part of the Node Discovery abstraction, so there is clear coupeling between those two abstraction. More details in CORE-836.
- Disconnect
Disconnect is currently send by TcpTransportLayer when it shuts down (Disconnect is being broadcast). This method is NOT needed as nodes should realize that other peers disconnect regardlessly if they managed to shut down gracefully or not. This message will be removed from the Protocol object (see CORE-838 for details).
- Any upstream
This is a placeholder for ANY possible message that is build on top Protocol. Effectively this is where messages from RChain protocol will be placed. Originally was designed to decouple TransportLayer, NodeDiscovery and RChain protocol (not successfully). This coupeling should be removed, see CORE-839 for details.
- Ping, Pong, Loookup, LookupResponse
...
Diagram below shows dependency usage between all three abstractions in the ideal world
+-------------------------+ | | | RChain Protocol | | | +-------------------------+ | | uses |uses v | | +-----------+ | | | | | Node | | | Discovery | | | | | +-----------+ | | v v uses +--------------------+ | Transport Layer | +--------------------+
That's the dream. Reality is...
...
1.4 Detailed description of abstractions
Below detailed description of how the abstractions are currently implemented and what are the issues that have to be addressed.
1.4.1 Transport Layer
1.4.2 Node Discovery
Below we describe how Node Discovery works currently
- Relation to Transport Layer
Node discovery is using Tranport Layer to fullfil its work. It uses
+----------------+ | | | NODE DISCOVERY | | | +----------------+ | v uses +----------------+ | TRANSPORT | | LAYER | +----------------+
This is almost true, as mentioned in previous section, TransportLayer sends messages of type Protocol (routing.proto) that are very Kademlia specific. See CORE-838 and CORE-839 to see the issue how to remove that cyclic dependency between Node Discovery and Transport Layer.
2. How current Kademlia implementation is different from the original paper
...