hostnetwork

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

README

Insolar – Host Network

Physical networking layer

Go Report Card GoDoc

Overview

We took Kademlia DHT original specifications and made significant improvements to make it ready for real world application by enterprises.

Key features of our blockchain network layer:
  • Support of heterogeneous network topology with different types of hosts being able to communicate with each other. In classic peer-to-peer networks, any host can communicate directly with any other host on the network. In a real enterprise environment, this condition is often unacceptable for a variety of reasons including security.
  • Network routing with a host or host group becoming relays for others hosts. The network can continue to function despite various network restrictions such as firewalls, NATs, etc.
  • Ability to limit number of gateways to corporate host group via relays to keep the host group secure while being able to interact with the rest of the network through relays. This feature mitigates the risk of DDoS attacks.

Key components

Transport

Network transport interface. It allows to abstract our network from physical transport. It can either be IP based network or any other kind of packet courier (e.g. an industrial packet bus).

Host

Host is a fundamental part of networking system. Each host has:

  • one real network address (IP or any other transport protocol address)
  • multiple abstract network IDs (either host's own or ones belonging to relayed hosts)
Routing

It is actually a Kademlia hash table used to store network hosts and calculate distances between them. See Kademlia whitepaper and XLattice design specification for details.

Packet

A set of data transferred by this module between hosts.

  • Request packet
  • Response packet

Now packets are serialized simply with encoding/gob. In future there will be a powerful robust serialization system based on Google's Protocol Buffers.

RPC

RPC module allows higher level components to register methods that can be called by other network hosts.

Configuration

Default Host Network config:

host:
  transport:
    protocol: UTP
    address: 127.0.0.1:0
    behindnat: true
  bootstraphosts: []
  isrelay: false

The listen port is zero(which means random) for unit test purpose. For host bootstrapping you need to fill bootstraphosts slice. See godoc for more details.

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()
}

For more detailed usage example see cmd/example/network/hostnetwork/main.go

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

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 Context

type Context context.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 NewHostNetwork added in v0.0.5

func NewHostNetwork(cfg configuration.HostNetwork) (*DHT, error)

NewHostNetwork creates and returns DHT network.

func (*DHT) AnalyzeNetwork

func (dht *DHT) AnalyzeNetwork(ctx Context) error

AnalyzeNetwork is func to analyze the network after IP obtaining.

func (*DHT) AuthenticationRequest

func (dht *DHT) AuthenticationRequest(ctx Context, command, targetID string) error

AuthenticationRequest sends an authentication request.

func (*DHT) Bootstrap

func (dht *DHT) Bootstrap() error

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) CheckNodeRole added in v0.0.5

func (dht *DHT) CheckNodeRole(ctx Context, domainID string) error

CheckNodeRole starting a check all known nodes.

func (*DHT) CheckOriginRequest

func (dht *DHT) CheckOriginRequest(ctx Context, targetID string) error

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) FindHost

func (dht *DHT) FindHost(ctx Context, key string) (*host.Host, bool, error)

FindHost returns target host's real network address.

func (*DHT) Get

func (dht *DHT) Get(ctx Context, key string) ([]byte, bool, error)

Get retrieves data from the transport using key. Key is the base58 encoded identifier of the data.

func (*DHT) GetDistance

func (dht *DHT) GetDistance(id1, id2 []byte) *big.Int

GetDistance returns a distance between id1 and id2.

func (*DHT) GetOriginHost added in v0.0.5

func (dht *DHT) GetOriginHost(ctx Context) *host.Host

GetOriginHost returns the local host.

func (*DHT) Listen

func (dht *DHT) Listen() error

Listen begins listening on the socket for incoming Packets.

func (*DHT) NumHosts

func (dht *DHT) NumHosts(ctx Context) int

NumHosts returns the total number of hosts stored in the local routing table.

func (*DHT) ObtainIP

func (dht *DHT) ObtainIP(ctx Context) error

ObtainIP starts to self IP obtaining.

func (*DHT) ObtainIPRequest

func (dht *DHT) ObtainIPRequest(ctx Context, targetID string) error

ObtainIPRequest is request to self IP obtaining.

func (*DHT) RelayRequest

func (dht *DHT) RelayRequest(ctx Context, command, targetID string) error

RelayRequest sends relay request to target.

func (*DHT) RemoteProcedureCall

func (dht *DHT) RemoteProcedureCall(ctx 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) Store

func (dht *DHT) Store(ctx Context, data []byte) (id string, err error)

Store stores data on the network. This will trigger an iterateStore loop. The base58 encoded identifier will be returned if the store is successful.

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 core.RemoteProcedure)
}

RPC is remote procedure call interface

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL