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/network/hostnetwork/connection" "github.com/insolar/insolar/network/hostnetwork/host" "github.com/insolar/insolar/network/hostnetwork/relay" "github.com/insolar/insolar/network/hostnetwork/resolver" "github.com/insolar/insolar/network/hostnetwork/rpc" "github.com/insolar/insolar/network/hostnetwork/store" "github.com/insolar/insolar/network/hostnetwork/transport" ) func main() { configuration := hostnetwork.NewNetworkConfiguration( resolver.NewStunResolver(""), connection.NewConnectionFactory(), transport.NewUTPTransportFactory(), store.NewMemoryStoreFactory(), rpc.NewRPCFactory(map[string]rpc.RemoteProcedure{}), relay.NewProxy()) dhtNetwork, err := configuration.CreateNetwork("0.0.0.0:31337", &hostnetwork.Options{}) if err != nil { panic(err) } defer configuration.CloseNetwork() dhtNetwork.Listen() }
Index ¶
- type AuthInfo
- type Configuration
- type Context
- type ContextBuilder
- type DHT
- func (dht *DHT) AnalyzeNetwork(ctx Context) error
- func (dht *DHT) AuthenticationRequest(ctx Context, command, targetID string) error
- func (dht *DHT) Bootstrap() error
- func (dht *DHT) CheckOriginRequest(ctx Context, targetID string) error
- func (dht *DHT) Disconnect()
- func (dht *DHT) FindHost(ctx Context, key string) (*host.Host, bool, error)
- func (dht *DHT) Get(ctx Context, key string) ([]byte, bool, error)
- func (dht *DHT) GetDistance(id1, id2 []byte) *big.Int
- func (dht *DHT) GetOriginID(ctx Context) string
- func (dht *DHT) Listen() error
- func (dht *DHT) NumHosts(ctx Context) int
- func (dht *DHT) ObtainIP(ctx Context) error
- func (dht *DHT) ObtainIPRequest(ctx Context, targetID string) error
- func (dht *DHT) RelayRequest(ctx Context, command, targetID string) error
- func (dht *DHT) RemoteProcedureCall(ctx Context, target string, method string, args [][]byte) (result []byte, err error)
- func (dht *DHT) RemoteProcedureRegister(name string, method RemoteProcedure)
- func (dht *DHT) Store(ctx Context, data []byte) (id string, err error)
- type HighKnownOuterHostsHost
- type Options
- type RPC
- type RemoteProcedure
- type Subnet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthInfo ¶
type AuthInfo struct { // Sent/received unique auth keys. SentKeys map[string][]byte ReceivedKeys map[string][]byte // contains filtered or unexported fields }
AuthInfo collects some information about authentication.
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration is a helper to initialize network easily.
func NewNetworkConfiguration ¶
func NewNetworkConfiguration( addressResolver resolver.PublicAddressResolver, connectionFactory connection.Factory, transportFactory transport.Factory, storeFactory store.Factory, rpcFactory rpc.Factory, proxy relay.Proxy, ) *Configuration
NewNetworkConfiguration creates new Configuration.
func (*Configuration) CloseNetwork ¶
func (cfg *Configuration) CloseNetwork() error
CloseNetwork stops networking.
func (*Configuration) CreateNetwork ¶
func (cfg *Configuration) CreateNetwork(address string, options *Options) (*DHT, error)
CreateNetwork creates and returns DHT network with parameters stored in Configuration.
type Context ¶
Context type is localized for future purposes. Network Host can have multiple IDs, but each action must be executed with only one ID. Context is used in all actions to select specific ID to work with.
type ContextBuilder ¶
type ContextBuilder struct {
// contains filtered or unexported fields
}
ContextBuilder allows to lazy configure and build new Context.
func NewContextBuilder ¶
func NewContextBuilder(dht *DHT) ContextBuilder
NewContextBuilder creates new ContextBuilder.
func (ContextBuilder) Build ¶
func (cb ContextBuilder) Build() (ctx 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, rpc rpc.RPC, options *Options, proxy relay.Proxy) (dht *DHT, err error)
NewDHT initializes a new DHT host.
func (*DHT) AnalyzeNetwork ¶
AnalyzeNetwork is func to analyze the network after IP obtaining.
func (*DHT) AuthenticationRequest ¶
AuthenticationRequest sends an authentication request.
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) CheckOriginRequest ¶
CheckOriginRequest send a request to check target host originality
func (*DHT) Disconnect ¶
func (dht *DHT) Disconnect()
Disconnect will trigger a Stop from the network.
func (*DHT) Get ¶
Get retrieves data from the transport using key. Key is the base58 encoded identifier of the data.
func (*DHT) GetDistance ¶
GetDistance returns a distance between id1 and id2.
func (*DHT) GetOriginID ¶
GetOriginID returns the base58 encoded identifier of the local host.
func (*DHT) NumHosts ¶
NumHosts returns the total number of hosts stored in the local routing table.
func (*DHT) ObtainIPRequest ¶
ObtainIPRequest is request to self IP obtaining.
func (*DHT) RelayRequest ¶
RelayRequest sends relay request to target.
func (*DHT) RemoteProcedureCall ¶
func (dht *DHT) RemoteProcedureCall(ctx Context, target 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 RemoteProcedure)
RemoteProcedureRegister registers procedure for remote call on this host
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 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 RPC ¶
type RPC interface { RemoteProcedureCall(ctx Context, target string, method string, args [][]byte) (result []byte, err error) RemoteProcedureRegister(name string, method RemoteProcedure) }
RPC is remote procedure call interface
type RemoteProcedure ¶
RemoteProcedure is remote procedure call function.
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. |