Documentation ¶
Overview ¶
Package hostnetwork is an implementation of Kademlia DHT. It is mostly based on original specification but has multiple backward-incompatible changes.
Usage:
package main import ( "github.com/insolar/insolar/network/hostnetwork" "github.com/insolar/insolar/configuration" ) func main() { cfg := configuration.NewConfiguration().Host cfg.Address = "0.0.0.0:31337" network, err := hostnetwork.NewHostNetwork(cfg) if err != nil { panic(err) } defer network.Disconnect() network.Listen() }
Index ¶
- Constants
- func AuthenticationRequest(hostHandler hosthandler.HostHandler, command, targetID string) error
- func BuildContext(cb ContextBuilder, msg *packet.Packet) hosthandler.Context
- func CascadeSendMessage(hostHandler hosthandler.HostHandler, data core.Cascade, targetID string, ...) error
- func CheckOriginRequest(hostHandler hosthandler.HostHandler, targetID string) error
- func CreateDHTContext(handler hosthandler.HostHandler) hosthandler.Context
- func DispatchPacketType(hostHandler hosthandler.HostHandler, ctx hosthandler.Context, ...) (*packet.Packet, error)
- func GetDefaultCtx(hostHandler hosthandler.HostHandler) hosthandler.Context
- func GetNonceRequest(hostHandler hosthandler.HostHandler, targetID string) ([]*core.Node, error)
- func NewDhtHostNetwork(conf configuration.Configuration, certificate core.Certificate, ...) (network.HostNetwork, error)
- func NewDhtNetworkController(network network.HostNetwork) (network.Controller, error)
- func NewNetworkConsensus(network network.HostNetwork) consensus.Processor
- func ObtainIPRequest(hostHandler hosthandler.HostHandler, targetID string) error
- func ParseIncomingPacket(hostHandler hosthandler.HostHandler, ctx hosthandler.Context, ...) (*packet.Packet, error)
- func RelayOwnershipRequest(hostHandler hosthandler.HostHandler, targetID string) error
- func RelayRequest(hostHandler hosthandler.HostHandler, command, targetID string) error
- func ResendPulseToKnownHosts(hostHandler hosthandler.HostHandler, hosts []host.Host, ...)
- func SendRelayOwnership(hostHandler hosthandler.HostHandler, subnetIDs []string)
- type AuthInfo
- type ContextBuilder
- type DHT
- func (dht *DHT) AddActiveNodes(activeNodes []*core.Node) error
- func (dht *DHT) AddAuthSentKey(id string, key []byte)
- func (dht *DHT) AddHost(ctx hosthandler.Context, host *routing.RouteHost)
- func (dht *DHT) AddPossibleProxyID(id string)
- func (dht *DHT) AddPossibleRelayID(id string)
- func (dht *DHT) AddProxyHost(targetID string)
- func (dht *DHT) AddReceivedKey(target string, key []byte)
- func (dht *DHT) AddRelayClient(host *host.Host) error
- func (dht *DHT) AddSubnetID(ip, targetID string)
- func (dht *DHT) AddUnsync(nodeID core.RecordRef, roles []core.NodeRole, address string, version string) (chan *core.Node, error)
- func (dht *DHT) AnalyzeNetwork(ctx hosthandler.Context) error
- func (dht *DHT) Bootstrap() error
- func (dht *DHT) CascadeSendMessage(data core.Cascade, targetID string, method string, args [][]byte) error
- func (dht *DHT) CheckNodeRole(domainID string) error
- func (dht *DHT) ConfirmNodeRole(roleKey string) bool
- func (dht *DHT) Disconnect()
- func (dht *DHT) EqualAuthSentKey(targetID string, key []byte) bool
- func (dht *DHT) FindHost(ctx hosthandler.Context, key string) (*host.Host, bool, error)
- func (dht *DHT) Get(ctx hosthandler.Context, key string) ([]byte, bool, error)
- func (dht *DHT) GetActiveNodesList() []*core.Node
- func (dht *DHT) GetExpirationTime(ctx hosthandler.Context, key []byte) time.Time
- func (dht *DHT) GetHighKnownHostID() string
- func (dht *DHT) GetHostsFromBootstrap()
- func (dht *DHT) GetNetworkCommonFacade() hosthandler.NetworkCommonFacade
- func (dht *DHT) GetNodeID() core.RecordRef
- func (dht *DHT) GetOriginHost() *host.Origin
- func (dht *DHT) GetOuterHostsCount() int
- func (dht *DHT) GetPacketTimeout() time.Duration
- func (dht *DHT) GetPrivateKey() *ecdsa.PrivateKey
- func (dht *DHT) GetProxyHostsCount() int
- func (dht *DHT) GetReplicationTime() time.Duration
- func (dht *DHT) GetSelfKnownOuterHosts() int
- func (dht *DHT) HostIsAuthenticated(targetID string) bool
- func (dht *DHT) HtFromCtx(ctx hosthandler.Context) *routing.HashTable
- func (dht *DHT) InvokeRPC(sender *host.Host, method string, args [][]byte) ([]byte, error)
- func (dht *DHT) KeyIsReceived(key string) ([]byte, bool)
- func (dht *DHT) Listen() error
- func (dht *DHT) NumHosts(ctx hosthandler.Context) int
- func (dht *DHT) ObtainIP() error
- func (dht *DHT) RemoteProcedureCall(ctx hosthandler.Context, targetID string, method string, args [][]byte) (result []byte, err error)
- func (dht *DHT) RemoteProcedureRegister(name string, method core.RemoteProcedure)
- func (dht *DHT) RemoveAuthHost(key string)
- func (dht *DHT) RemoveAuthSentKeys(targetID string)
- func (dht *DHT) RemovePossibleProxyID(id string)
- func (dht *DHT) RemoveProxyHost(targetID string)
- func (dht *DHT) RemoveRelayClient(host *host.Host) error
- func (dht *DHT) SendRequest(packet *packet.Packet) (transport.Future, error)
- func (dht *DHT) SetAuthStatus(targetID string, status bool)
- func (dht *DHT) SetHighKnownHostID(id string)
- func (dht *DHT) SetNodeKeeper(keeper network.NodeKeeper)
- func (dht *DHT) SetOuterHostsCount(hosts int)
- func (dht *DHT) StartAuthorize() error
- func (dht *DHT) Store(key store.Key, data []byte, replication time.Time, expiration time.Time, ...) error
- func (dht *DHT) StoreData(ctx hosthandler.Context, data []byte) (id string, err error)
- func (dht *DHT) StoreRetrieve(key store.Key) ([]byte, bool)
- type HighKnownOuterHostsHost
- type MockLedger
- type MockPulseManager
- type Options
- type Subnet
- type Wrapper
- func (w *Wrapper) AnalyzeNetwork() error
- func (w *Wrapper) Authorize() error
- func (w *Wrapper) Bootstrap() error
- func (w *Wrapper) BuildResponse(request network.Request, responseData interface{}) network.Response
- func (w *Wrapper) GetConsensus() consensus.Processor
- func (w *Wrapper) GetNodeID() core.RecordRef
- func (w *Wrapper) Inject(components core.Components)
- func (w *Wrapper) NewRequestBuilder() network.RequestBuilder
- func (w *Wrapper) PublicAddress() string
- func (w *Wrapper) RegisterRequestHandler(t types.PacketType, handler network.RequestHandler)
- func (w *Wrapper) RemoteProcedureRegister(name string, method core.RemoteProcedure)
- func (w *Wrapper) ResendPulseToKnownHosts(pulse core.Pulse)
- func (w *Wrapper) SendCascadeMessage(data core.Cascade, method string, msg core.SignedMessage) error
- func (w *Wrapper) SendMessage(nodeID core.RecordRef, method string, msg core.SignedMessage) ([]byte, error)
- func (w *Wrapper) SendRequest(network.Request, core.RecordRef) (network.Future, error)
- func (w *Wrapper) Start()
- func (w *Wrapper) Stop()
Constants ¶
const ( CtxTableIndex = ctxKey("table_index") DefaultHostID = 0 )
Variables ¶
This section is empty.
Functions ¶
func AuthenticationRequest ¶
func AuthenticationRequest(hostHandler hosthandler.HostHandler, command, targetID string) error
AuthenticationRequest sends an authentication request.
func BuildContext ¶
func BuildContext(cb ContextBuilder, msg *packet.Packet) hosthandler.Context
BuildContext builds a context for packet.
func CascadeSendMessage ¶
func CascadeSendMessage(hostHandler hosthandler.HostHandler, data core.Cascade, targetID string, method string, args [][]byte) error
CascadeSendMessage sends a message to the next cascade layer.
func CheckOriginRequest ¶
func CheckOriginRequest(hostHandler hosthandler.HostHandler, targetID string) error
CheckOriginRequest send a request to check target host originality
func CreateDHTContext ¶
func CreateDHTContext(handler hosthandler.HostHandler) hosthandler.Context
func DispatchPacketType ¶
func DispatchPacketType( hostHandler hosthandler.HostHandler, ctx hosthandler.Context, msg *packet.Packet, packetBuilder packet.Builder, ) (*packet.Packet, error)
DispatchPacketType checks message type.
func GetDefaultCtx ¶
func GetDefaultCtx(hostHandler hosthandler.HostHandler) hosthandler.Context
GetDefaultCtx creates default context for the host handler.
func GetNonceRequest ¶
func GetNonceRequest(hostHandler hosthandler.HostHandler, targetID string) ([]*core.Node, error)
func NewDhtHostNetwork ¶
func NewDhtHostNetwork(conf configuration.Configuration, certificate core.Certificate, pulseCallback network.OnPulse) (network.HostNetwork, error)
func NewDhtNetworkController ¶
func NewDhtNetworkController(network network.HostNetwork) (network.Controller, error)
func NewNetworkConsensus ¶
func NewNetworkConsensus(network network.HostNetwork) consensus.Processor
func ObtainIPRequest ¶
func ObtainIPRequest(hostHandler hosthandler.HostHandler, targetID string) error
ObtainIPRequest is request to self IP obtaining.
func ParseIncomingPacket ¶
func ParseIncomingPacket(hostHandler hosthandler.HostHandler, ctx hosthandler.Context, msg *packet.Packet, packetBuilder packet.Builder) (*packet.Packet, error)
ParseIncomingPacket detects a packet type.
func RelayOwnershipRequest ¶
func RelayOwnershipRequest(hostHandler hosthandler.HostHandler, targetID string) error
RelayOwnershipRequest sends a relay ownership request.
func RelayRequest ¶
func RelayRequest(hostHandler hosthandler.HostHandler, command, targetID string) error
RelayRequest sends relay request to target.
func ResendPulseToKnownHosts ¶
func ResendPulseToKnownHosts(hostHandler hosthandler.HostHandler, hosts []host.Host, pulse *packet.RequestPulse)
ResendPulseToKnownHosts resends received pulse to all known hosts
func SendRelayOwnership ¶
func SendRelayOwnership(hostHandler hosthandler.HostHandler, subnetIDs []string)
SendRelayOwnership send a relay ownership request.
Types ¶
type AuthInfo ¶
type AuthInfo struct { // Sent/received unique auth keys. SentKeys map[string][]byte ReceivedKeys map[string][]byte AuthenticatedHosts map[string]bool }
AuthInfo collects some information about authentication.
type ContextBuilder ¶
type ContextBuilder struct {
// contains filtered or unexported fields
}
ContextBuilder allows to lazy configure and build new Context.
func NewContextBuilder ¶
func NewContextBuilder(hostHandler hosthandler.HostHandler) ContextBuilder
NewContextBuilder creates new ContextBuilder.
func (ContextBuilder) Build ¶
func (cb ContextBuilder) Build() (ctx hosthandler.Context, err error)
Build builds and returns new Context.
func (ContextBuilder) SetDefaultHost ¶
func (cb ContextBuilder) SetDefaultHost() ContextBuilder
SetDefaultHost sets first host id in Context.
func (ContextBuilder) SetHostByID ¶
func (cb ContextBuilder) SetHostByID(hostID id.ID) ContextBuilder
SetHostByID sets host id in Context.
type DHT ¶
type DHT struct {
// contains filtered or unexported fields
}
DHT represents the state of the local host in the distributed hash table.
func NewDHT ¶
func NewDHT( store store.Store, origin *host.Origin, transport transport.Transport, ncf hosthandler.NetworkCommonFacade, options *Options, proxy relay.Proxy, timeout int, infbootstrap bool, nodeID core.RecordRef, majorityRule int, certificate core.Certificate, ) (dht *DHT, err error)
NewDHT initializes a new DHT host.
func NewHostNetwork ¶
func NewHostNetwork( cfg configuration.Configuration, cascade *cascade.Cascade, certificate core.Certificate, pulseCallback network.OnPulse, ) (*DHT, error)
NewHostNetwork creates and returns DHT network.
func (*DHT) AddActiveNodes ¶
AddActiveNodes adds an active nodes slice.
func (*DHT) AddAuthSentKey ¶
AddAuthSentKey adds a sent key to auth.
func (*DHT) AddHost ¶
func (dht *DHT) AddHost(ctx hosthandler.Context, host *routing.RouteHost)
AddHost adds a host into the appropriate k bucket we store these buckets in big-endian order so we look at the bits from right to left in order to find the appropriate bucket
func (*DHT) AddPossibleProxyID ¶
AddPossibleProxyID adds an id which could be a proxy.
func (*DHT) AddPossibleRelayID ¶
AddPossibleRelayID add a host id which can be a relay.
func (*DHT) AddProxyHost ¶
AddProxyHost adds a proxy host.
func (*DHT) AddReceivedKey ¶
AddReceivedKey adds a new received key from target.
func (*DHT) AddRelayClient ¶
AddRelayClient adds a new relay client.
func (*DHT) AddSubnetID ¶
AddSubnetID adds a subnet ID.
func (*DHT) AnalyzeNetwork ¶
func (dht *DHT) AnalyzeNetwork(ctx hosthandler.Context) error
AnalyzeNetwork is func to analyze the network after IP obtaining.
func (*DHT) Bootstrap ¶
Bootstrap attempts to bootstrap the network using the BootstrapHosts provided to the Options struct. This will trigger an iterateBootstrap to the provided BootstrapHosts.
func (*DHT) CascadeSendMessage ¶
func (dht *DHT) CascadeSendMessage(data core.Cascade, targetID string, method string, args [][]byte) error
CascadeSendMessage sends a message to the next cascade layer.
func (*DHT) CheckNodeRole ¶
CheckNodeRole starting a check all known nodes.
func (*DHT) ConfirmNodeRole ¶
ConfirmNodeRole is a node role confirmation.
func (*DHT) Disconnect ¶
func (dht *DHT) Disconnect()
Disconnect will trigger a Stop from the network.
func (*DHT) EqualAuthSentKey ¶
EqualAuthSentKey returns true if a given key equals to targetID key.
func (*DHT) Get ¶
Get retrieves data from the transport using key. Key is the base58 encoded identifier of the data.
func (*DHT) GetActiveNodesList ¶
GetActiveNodesList returns an active nodes list.
func (*DHT) GetExpirationTime ¶
GetExpirationTime returns a expiration time after which a key/value pair expires.
func (*DHT) GetHighKnownHostID ¶
GetHighKnownHostID returns a high known host ID.
func (*DHT) GetHostsFromBootstrap ¶
func (dht *DHT) GetHostsFromBootstrap()
func (*DHT) GetNetworkCommonFacade ¶
func (dht *DHT) GetNetworkCommonFacade() hosthandler.NetworkCommonFacade
GetNetworkCommonFacade returns a networkcommonfacade ptr.
func (*DHT) GetOriginHost ¶
GetOriginHost returns the local host.
func (*DHT) GetOuterHostsCount ¶
GetOuterHostsCount returns a outer hosts count.
func (*DHT) GetPacketTimeout ¶
GetPacketTimeout returns the maximum time to wait for a response to any packet.
func (*DHT) GetPrivateKey ¶
func (dht *DHT) GetPrivateKey() *ecdsa.PrivateKey
GetPrivateKey returns a private key.
func (*DHT) GetProxyHostsCount ¶
GetProxyHostsCount returns a proxy hosts count.
func (*DHT) GetReplicationTime ¶
GetReplicationTime returns a interval between Kademlia replication events.
func (*DHT) GetSelfKnownOuterHosts ¶
GetSelfKnownOuterHosts return a self known hosts count.
func (*DHT) HostIsAuthenticated ¶
HostIsAuthenticated returns true if target ID is authenticated host.
func (*DHT) HtFromCtx ¶
func (dht *DHT) HtFromCtx(ctx hosthandler.Context) *routing.HashTable
HtFromCtx returns a routing hashtable known by ctx.
func (*DHT) KeyIsReceived ¶
KeyIsReceived returns true and a key from targetID if exist.
func (*DHT) NumHosts ¶
func (dht *DHT) NumHosts(ctx hosthandler.Context) int
NumHosts returns the total number of hosts stored in the local routing table.
func (*DHT) RemoteProcedureCall ¶
func (dht *DHT) RemoteProcedureCall(ctx hosthandler.Context, targetID string, method string, args [][]byte) (result []byte, err error)
RemoteProcedureCall calls remote procedure on target host.
func (*DHT) RemoteProcedureRegister ¶
func (dht *DHT) RemoteProcedureRegister(name string, method core.RemoteProcedure)
RemoteProcedureRegister registers procedure for remote call on this host
func (*DHT) RemoveAuthHost ¶
RemoveAuthHost removes a host from auth.
func (*DHT) RemoveAuthSentKeys ¶
RemoveAuthSentKeys removes a targetID from sent keys.
func (*DHT) RemovePossibleProxyID ¶
RemovePossibleProxyID removes if from possible proxy ids list.
func (*DHT) RemoveProxyHost ¶
RemoveProxyHost removes host from proxy list.
func (*DHT) RemoveRelayClient ¶
RemoveRelayClient removes a client from relay list.
func (*DHT) SendRequest ¶
SendRequest sends a packet.
func (*DHT) SetAuthStatus ¶
SetAuthStatus sets a new auth status to targetID.
func (*DHT) SetHighKnownHostID ¶
SetHighKnownHostID sets a new high known host ID.
func (*DHT) SetNodeKeeper ¶
func (dht *DHT) SetNodeKeeper(keeper network.NodeKeeper)
func (*DHT) SetOuterHostsCount ¶
SetOuterHostsCount sets a new value to outer hosts count.
func (*DHT) StartAuthorize ¶
StartAuthorize start authorize to discovery nodes.
func (*DHT) Store ¶
func (dht *DHT) Store(key store.Key, data []byte, replication time.Time, expiration time.Time, publisher bool) error
Store should store a key/value pair for the local host with the given replication and expiration times.
type HighKnownOuterHostsHost ¶
type HighKnownOuterHostsHost struct { ID string OuterHosts int // high known outer hosts by ID host SelfKnownOuterHosts int }
HighKnownOuterHostsHost collects an information about host in home subnet which have a more known outer hosts.
type MockLedger ¶
type MockLedger struct {
// contains filtered or unexported fields
}
func (*MockLedger) GetArtifactManager ¶
func (l *MockLedger) GetArtifactManager() core.ArtifactManager
GetArtifactManager returns artifact manager to work with.
func (*MockLedger) GetJetCoordinator ¶
func (l *MockLedger) GetJetCoordinator() core.JetCoordinator
GetJetCoordinator returns jet coordinator to work with.
func (*MockLedger) GetPulseManager ¶
func (l *MockLedger) GetPulseManager() core.PulseManager
GetPulseManager returns pulse manager to work with.
type MockPulseManager ¶
type MockPulseManager struct {
// contains filtered or unexported fields
}
MockPulseManager mock struct to read and write pulse that implements core.PulseManager interface.
func (*MockPulseManager) SetCallback ¶
func (pm *MockPulseManager) SetCallback(callback func(core.Pulse))
type Options ¶
type Options struct { // The hosts being used to bootstrap the network. Without a bootstrap // host there is no way to connect to the network. NetworkHosts can be // initialized via host.NewHost(). BootstrapHosts []*host.Host // The time after which a key/value pair expires; // this is a time-to-live (TTL) from the original publication date. ExpirationTime time.Duration // Seconds after which an otherwise unaccessed bucket must be refreshed. RefreshTime time.Duration // The interval between Kademlia replication events, when a host is // required to publish its entire database. ReplicateTime time.Duration // The time after which the original publisher must // republish a key/value pair. Currently not implemented. RepublishTime time.Duration // The maximum time to wait for a response from a host before discarding // it from the bucket. PingTimeout time.Duration // The maximum time to wait for a response to any packet. PacketTimeout time.Duration }
Options contains configuration options for the local host.
type Subnet ¶
type Subnet struct { SubnetIDs map[string][]string // key - ip, value - id HomeSubnetKey string // key of home subnet fo SubnetIDs PossibleRelayIDs []string PossibleProxyIDs []string HighKnownHosts HighKnownOuterHostsHost }
Subnet collects some information about self network part
type Wrapper ¶
type Wrapper struct {
HostNetwork hosthandler.HostHandler
}
func (*Wrapper) AnalyzeNetwork ¶
AnalyzeNetwork legacy method for old DHT network (should be removed in
func (*Wrapper) Bootstrap ¶
Bootstrap init bootstrap process: 1. Connect to discovery node; 2. Reconnect to new discovery node if redirected.
func (*Wrapper) BuildResponse ¶
func (*Wrapper) GetConsensus ¶
func (*Wrapper) Inject ¶
func (w *Wrapper) Inject(components core.Components)
Inject inject components
func (*Wrapper) NewRequestBuilder ¶
func (w *Wrapper) NewRequestBuilder() network.RequestBuilder
NewRequestBuilder create packet builder for an outgoing request with sender set to current node.
func (*Wrapper) PublicAddress ¶
PublicAddress returns public address that can be published for all nodes.
func (*Wrapper) RegisterRequestHandler ¶
func (w *Wrapper) RegisterRequestHandler(t types.PacketType, handler network.RequestHandler)
RegisterRequestHandler register a handler function to process incoming requests of a specific type.
func (*Wrapper) RemoteProcedureRegister ¶
func (w *Wrapper) RemoteProcedureRegister(name string, method core.RemoteProcedure)
RemoteProcedureRegister register remote procedure that will be executed when message is received
func (*Wrapper) ResendPulseToKnownHosts ¶
ResendPulseToKnownHosts resend pulse when we receive pulse from pulsar daemon
func (*Wrapper) SendCascadeMessage ¶
func (*Wrapper) SendMessage ¶
func (w *Wrapper) SendMessage(nodeID core.RecordRef, method string, msg core.SignedMessage) ([]byte, error)
SendMessage send message to nodeID
func (*Wrapper) SendRequest ¶
SendRequest send request to a remote node.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package routing implements Kademlia hash tables with XOR distance metrics.
|
Package routing implements Kademlia hash tables with XOR distance metrics. |
Package rpc allows higher level components to register methods that can be called by other network hosts.
|
Package rpc allows higher level components to register methods that can be called by other network hosts. |
Package store provides interfaces and default in-memory implementation of storage for DHT metadata.
|
Package store provides interfaces and default in-memory implementation of storage for DHT metadata. |