host

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2018 License: Apache-2.0 Imports: 18 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 nodes being able to communicate with each other. In classic peer-to-peer networks, any node can communicate directly with any other node on the network. In a real enterprise environment, this condition is often unacceptable for a variety of reasons including security.
  • Network routing with a node or node group becoming relays for others nodes. The network can continue to function despite various network restrictions such as firewalls, NATs, etc.
  • Ability to limit number of gateways to corporate node group via relays to keep the node 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 message courier (e.g. an industrial message bus).

Node

Node is a fundamental part of networking system. Each node has:

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

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

Message

A set of data transferred by this module between nodes.

  • Request message
  • Response message

Now messages 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 nodes.

Usage

package main

import (
	"github.com/insolar/insolar/network/host"
	"github.com/insolar/insolar/network/host/connection"
	"github.com/insolar/insolar/network/host/node"
	"github.com/insolar/insolar/network/host/relay"
	"github.com/insolar/insolar/network/host/resolver"
	"github.com/insolar/insolar/network/host/rpc"
	"github.com/insolar/insolar/network/host/store"
	"github.com/insolar/insolar/network/host/transport"
)

func main() {
	configuration := host.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", &host.Options{})
	if err != nil {
		panic(err)
	}
	defer configuration.CloseNetwork()

	dhtNetwork.Listen()
}

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

Documentation

Overview

Package host 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"
	"github.com/insolar/insolar/connection"
	"github.com/insolar/insolar/node"
	"github.com/insolar/insolar/relay"
	"github.com/insolar/insolar/resolver"
	"github.com/insolar/insolar/rpc"
	"github.com/insolar/insolar/store"
	"github.com/insolar/insolar/transport"
)

func main() {
	configuration := insolar.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", &insolar.Options{})
	if err != nil {
		panic(err)
	}
	defer configuration.CloseNetwork()

	dhtNetwork.Listen()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	// contains filtered or unexported fields
}

Configuration is a helper to initialize insolar 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 insolar with parameters stored in Configuration.

type Context

type Context context.Context

Context type is localized for future purposes. Network Node 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) SetDefaultNode

func (cb ContextBuilder) SetDefaultNode() ContextBuilder

SetDefaultNode sets first node id in Context.

func (ContextBuilder) SetNodeByID

func (cb ContextBuilder) SetNodeByID(nodeID node.ID) ContextBuilder

SetNodeByID sets node id in Context.

type DHT

type DHT struct {
	// contains filtered or unexported fields
}

DHT represents the state of the local node in the distributed hash table.

func NewDHT

func NewDHT(store store.Store, origin *node.Origin, transport transport.Transport, rpc rpc.RPC, options *Options, proxy relay.Proxy) (dht *DHT, err error)

NewDHT initializes a new DHT node.

func (*DHT) Bootstrap

func (dht *DHT) Bootstrap() error

Bootstrap attempts to bootstrap the insolar using the BootstrapNodes provided to the Options struct. This will trigger an iterateBootstrap to the provided BootstrapNodes.

func (*DHT) Disconnect

func (dht *DHT) Disconnect()

Disconnect will trigger a Stop from the insolar.

func (*DHT) FindNode

func (dht *DHT) FindNode(ctx Context, key string) (*node.Node, bool, error)

FindNode returns target node's real insolar 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) GetOriginID

func (dht *DHT) GetOriginID(ctx Context) string

GetOriginID returns the base58 encoded identifier of the local node.

func (*DHT) Listen

func (dht *DHT) Listen() error

Listen begins listening on the socket for incoming Messages.

func (*DHT) NumNodes

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

NumNodes returns the total number of nodes stored in the local routing table.

func (*DHT) RelayRequest

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

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 node.

func (*DHT) Store

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

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

type Options

type Options struct {
	// The nodes being used to bootstrap the insolar. Without a bootstrap
	// node there is no way to connect to the insolar. NetworkNodes can be
	// initialized via insolar.NewNode().
	BootstrapNodes []*node.Node

	// 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 node 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 node before discarding
	// it from the bucket.
	PingTimeout time.Duration

	// The maximum time to wait for a response to any message.
	MessageTimeout time.Duration
}

Options contains configuration options for the local node.

Directories

Path Synopsis
Package connection encapsulates connection creation process and provides connection factories.
Package connection encapsulates connection creation process and provides connection factories.
Package message provides insolar messaging protocol and serialization layer.
Package message provides insolar messaging protocol and serialization layer.
Package node is a fundamental part of networking system.
Package node is a fundamental part of networking system.
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 insolar address.
Package resolver provides interface (and default implementation) to retrieve public insolar 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 insolar nodes.
Package rpc allows higher level components to register methods that can be called by other insolar nodes.
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 insolar transport interface.
Package transport provides insolar transport interface.

Jump to

Keyboard shortcuts

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