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 ¶
- 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 DispatchPacketType(hostHandler hosthandler.HostHandler, ctx hosthandler.Context, ...) (*packet.Packet, error)
- func GetDefaultCtx(hostHandler hosthandler.HostHandler) hosthandler.Context
- 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 []*routing.RouteHost, ...)
- func SendRelayOwnership(hostHandler hosthandler.HostHandler, subnetIDs []string)
- type AuthInfo
- type ContextBuilder
- type DHT
- 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) 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) 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) GetOriginHost() *host.Origin
- func (dht *DHT) GetOuterHostsCount() int
- func (dht *DHT) GetPacketTimeout() time.Duration
- 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) SetOuterHostsCount(hosts int)
- 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 MockPulseManager
- type Options
- type Subnet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthenticationRequest ¶ added in v0.2.0
func AuthenticationRequest(hostHandler hosthandler.HostHandler, command, targetID string) error
AuthenticationRequest sends an authentication request.
func BuildContext ¶ added in v0.2.0
func BuildContext(cb ContextBuilder, msg *packet.Packet) hosthandler.Context
BuildContext builds a context for packet.
func CascadeSendMessage ¶ added in v0.2.0
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 ¶ added in v0.2.0
func CheckOriginRequest(hostHandler hosthandler.HostHandler, targetID string) error
CheckOriginRequest send a request to check target host originality
func DispatchPacketType ¶ added in v0.2.0
func DispatchPacketType( hostHandler hosthandler.HostHandler, ctx hosthandler.Context, msg *packet.Packet, packetBuilder packet.Builder, ) (*packet.Packet, error)
DispatchPacketType checks message type.
func GetDefaultCtx ¶ added in v0.4.0
func GetDefaultCtx(hostHandler hosthandler.HostHandler) hosthandler.Context
GetDefaultCtx creates default context for the host handler.
func ObtainIPRequest ¶ added in v0.2.0
func ObtainIPRequest(hostHandler hosthandler.HostHandler, targetID string) error
ObtainIPRequest is request to self IP obtaining.
func ParseIncomingPacket ¶ added in v0.2.0
func ParseIncomingPacket(hostHandler hosthandler.HostHandler, ctx hosthandler.Context, msg *packet.Packet, packetBuilder packet.Builder) (*packet.Packet, error)
ParseIncomingPacket detects a packet type.
func RelayOwnershipRequest ¶ added in v0.2.0
func RelayOwnershipRequest(hostHandler hosthandler.HostHandler, targetID string) error
RelayOwnershipRequest sends a relay ownership request.
func RelayRequest ¶ added in v0.2.0
func RelayRequest(hostHandler hosthandler.HostHandler, command, targetID string) error
RelayRequest sends relay request to target.
func ResendPulseToKnownHosts ¶ added in v0.4.0
func ResendPulseToKnownHosts(hostHandler hosthandler.HostHandler, hosts []*routing.RouteHost, pulse *packet.RequestPulse)
ResendPulseToKnownHosts resends received pulse to all known hosts
func SendRelayOwnership ¶ added in v0.3.0
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, ) (dht *DHT, err error)
NewDHT initializes a new DHT host.
func NewHostNetwork ¶ added in v0.0.5
func NewHostNetwork(cfg configuration.HostNetwork, nn *nodenetwork.NodeNetwork, cascade *cascade.Cascade) (*DHT, error)
NewHostNetwork creates and returns DHT network.
func (*DHT) AddAuthSentKey ¶ added in v0.2.0
AddAuthSentKey adds a sent key to auth.
func (*DHT) AddHost ¶ added in v0.2.0
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 ¶ added in v0.2.0
AddPossibleProxyID adds an id which could be a proxy.
func (*DHT) AddPossibleRelayID ¶ added in v0.2.0
AddPossibleRelayID add a host id which can be a relay.
func (*DHT) AddProxyHost ¶ added in v0.2.0
AddProxyHost adds a proxy host.
func (*DHT) AddReceivedKey ¶ added in v0.2.0
AddReceivedKey adds a new received key from target.
func (*DHT) AddRelayClient ¶ added in v0.2.0
AddRelayClient adds a new relay client.
func (*DHT) AddSubnetID ¶ added in v0.2.0
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 ¶ added in v0.2.0
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 ¶ added in v0.0.5
CheckNodeRole starting a check all known nodes.
func (*DHT) ConfirmNodeRole ¶ added in v0.2.0
ConfirmNodeRole is a node role confirmation.
func (*DHT) Disconnect ¶
func (dht *DHT) Disconnect()
Disconnect will trigger a Stop from the network.
func (*DHT) EqualAuthSentKey ¶ added in v0.2.0
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) GetExpirationTime ¶ added in v0.2.0
GetExpirationTime returns a expiration time after which a key/value pair expires.
func (*DHT) GetHighKnownHostID ¶ added in v0.2.0
GetHighKnownHostID returns a high known host ID.
func (*DHT) GetHostsFromBootstrap ¶ added in v0.4.0
func (dht *DHT) GetHostsFromBootstrap()
func (*DHT) GetNetworkCommonFacade ¶ added in v0.2.0
func (dht *DHT) GetNetworkCommonFacade() hosthandler.NetworkCommonFacade
GetNetworkCommonFacade returns a networkcommonfacade ptr.
func (*DHT) GetOriginHost ¶ added in v0.0.5
GetOriginHost returns the local host.
func (*DHT) GetOuterHostsCount ¶ added in v0.2.0
GetOuterHostsCount returns a outer hosts count.
func (*DHT) GetPacketTimeout ¶ added in v0.2.0
GetPacketTimeout returns the maximum time to wait for a response to any packet.
func (*DHT) GetProxyHostsCount ¶ added in v0.2.0
GetProxyHostsCount returns a proxy hosts count.
func (*DHT) GetReplicationTime ¶ added in v0.2.0
GetReplicationTime returns a interval between Kademlia replication events.
func (*DHT) GetSelfKnownOuterHosts ¶ added in v0.2.0
GetSelfKnownOuterHosts return a self known hosts count.
func (*DHT) HostIsAuthenticated ¶ added in v0.2.0
HostIsAuthenticated returns true if target ID is authenticated host.
func (*DHT) HtFromCtx ¶ added in v0.2.0
func (dht *DHT) HtFromCtx(ctx hosthandler.Context) *routing.HashTable
HtFromCtx returns a routing hashtable known by ctx.
func (*DHT) KeyIsReceived ¶ added in v0.2.0
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 ¶ added in v0.2.0
RemoveAuthHost removes a host from auth.
func (*DHT) RemoveAuthSentKeys ¶ added in v0.2.0
RemoveAuthSentKeys removes a targetID from sent keys.
func (*DHT) RemovePossibleProxyID ¶ added in v0.2.0
RemovePossibleProxyID removes if from possible proxy ids list.
func (*DHT) RemoveProxyHost ¶ added in v0.2.0
RemoveProxyHost removes host from proxy list.
func (*DHT) RemoveRelayClient ¶ added in v0.2.0
RemoveRelayClient removes a client from relay list.
func (*DHT) SendRequest ¶ added in v0.2.0
SendRequest sends a packet.
func (*DHT) SetAuthStatus ¶ added in v0.2.0
SetAuthStatus sets a new auth status to targetID.
func (*DHT) SetHighKnownHostID ¶ added in v0.2.0
SetHighKnownHostID sets a new high known host ID.
func (*DHT) SetOuterHostsCount ¶ added in v0.2.0
SetOuterHostsCount sets a new value to outer hosts count.
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 MockPulseManager ¶ added in v0.4.0
type MockPulseManager struct {
// contains filtered or unexported fields
}
MockPulseManager mock struct to read and write pulse that implements core.PulseManager interface.
func (*MockPulseManager) Current ¶ added in v0.4.0
func (pm *MockPulseManager) Current() (*core.Pulse, error)
func (*MockPulseManager) Set ¶ added in v0.4.0
func (pm *MockPulseManager) Set(pulse core.Pulse) error
func (*MockPulseManager) SetCallback ¶ added in v0.4.0
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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package connection encapsulates connection creation process and provides connection factories.
|
Package connection encapsulates connection creation process and provides connection factories. |
Package host is a fundamental part of networking system.
|
Package host is a fundamental part of networking system. |
Package packet provides network messaging protocol and serialization layer.
|
Package packet provides network messaging protocol and serialization layer. |
Package relay is an implementation of relay mechanism.
|
Package relay is an implementation of relay mechanism. |
Package resolver provides interface (and default implementation) to retrieve public network address.
|
Package resolver provides interface (and default implementation) to retrieve public network address. |
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. |
Package transport provides network transport interface.
|
Package transport provides network transport interface. |