network
Last updated: 2024-09-27 10:47:23.671817 File source: link on GitLab
network
Table of Contents
Specification
Description
This package contains all network related code such as p2p communication, ip over libp2p and other networks that might be needed in the future.
Structure and Organisation
Here is quick overview of the contents of this pacakge:
README: Current file which is aimed towards developers who wish to use and modify the package functionality.
network: This file defines Network and Messenger interfaces and a method to create a new network.
types: This file defines the VPN interface.
libp2p: This contains code related to libp2p functionality.
specs: This contains class diagram of the package built in plantuml.
Class Diagram
The class diagram for the network package is shown below.
Source file
Rendered from source file
Functionality
TBD
Note: the functionality of DMS is being currently developed. See the proposed section for the suggested design of interfaces and methods.
Data Types
TBD
Note: the functionality of DMS is being currently developed. See the proposed section for the suggested data types.
Testing
TBD
Proposed Functionality / Requirements
List of issues
All issues that are related to the implementation of network
package can be found below. These include any proposals for modifications to the package or new data structures needed to cover the requirements of other packages.
Interfaces and methods
proposed
Network interface
Let's have a look at the methods and rationale behind them:
Config()
:
Config
is where host is prepared with desired settings. Settings are loaded from the file if required. An example in libp2p implementation would be to configure parameters which needs to be passed to libp2p.New()
method, it can also a good place to set the stream handlers.
Things like private network are configured at this point.
Init()
:
Init
or Start
starts up the host. This is a good place to start discovery and starting goroutines for fetching DHT update and updating peerstore.
EventRegister()
:
In libp2p, we can listen to specific events. EventRegister
is to set handler to such event. A few events in libp2p are:
EvtLocalAddressesUpdated
EvtLocalReachabilityChanged
EvtPeerIdentificationCompleted
EvtNATDeviceTypeChanged
EvtPeerConnectednessChanged
More events can be found here
Dial()
:
Dial
is for connecting to a peer. When peer A dials peer B, peer B has to Listen
to the incoming connection.
Listen()
:
Listen
is the counterpart to Dial
. Read more about listening and dialing here
Status()
:
TBD
All peers we are corrently connected to.
??
Stop()
:
Basically it's like shutting down the peer. It is opposite of Init
or Start
.
proposed
VPN interface
Let's have a look at the methods and background behind them:
TBD
: Parameter are still to be defined. Should we pass the peer ID? Or make it more generic to have IP addresses?
Start()
:
Start()
takes in initial list of hosts and assigns each peer a private IP.
AddPeer()
:
AddPeer()
is for adding a new peer to the VPN after the VPN is created. This should also update the routing table with the new peer. It should also not affect the existing peers, and should not lead to any IP collision.
RemovePeer()
:
RemovePeer()
should remove a peer from remove peers from the private network.
Stop()
:
TBD
: What should be done when the VPN is stopped? Should all the peers be removed from the network?
proposed
Internal APIs
publishJob
signature:
publishJob(dms.orchestrator.BidRequest)
input:
Bid request
output: None
publishJob
is responsible for publishing a request for bid to the network for a job received by the DMS.
There should be a top level package for set of functions/initlializers for management of:
TUN/TAP device
Virtual ethernet
Virtual switch
Firewall management
proposed
sendLibP2PMessage
sendLibP2PMessage
shall be called by dms.orchestrator.sendMessage()
function ito send the telemetry.Message
object via libP2P interface defined in network
package. It is a low level implementation of sending messages in NuNet network via libp2p.
proposed
receiveLibP2PMessage
TBD
proposed
processMessage
TBD
proposed
Private Swarm
Note: Private Swarm functionality is expected to be moved to libp2p sub-package once specific methods and interfaces have been defined
The private swarm functionality allows users to create and join a private network with some authorised peers. Note that these peers need to be identified beforehand to use this feature. It is also required that all peers have onboarded to the Nunet network and are using the same channel. It is because the identification of peers is done using libp2p public key generated during the onboarding process.
The creation of private network consists of the following operations.
Configure Private Network
The user who wants to create the private network should have a list of peer ids
it wants to authorise to join the private network. This process configures the network by creating a swarm key and a bootstrap node.
Exchange Swarm Key
The authorised user who wants to connect to the private network will request for a swarm key from the node that has configured the private network. The node which has created the swarm key shares it with the authorised user when requested. The authentication of the user is based on its public key.
Join Private Network
The DMS will disconnect from the public network and join the private network using the shared swarm key.
Disconnect Private Network
The DMS will disconnect from the private network and join the public network the user onboarded on to.
Rotate Swarm Key
The DMS will generate a new swarm key for the private network and notify the authorised users.
References
https://github.com/libp2p/go-libp2p/tree/master/core/event
https://docs.libp2p.io/concepts/transports/listen-and-dial/
Last updated