network

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2018 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version            = 0
	ProtocolLength     = uint64(8)
	ProtocolMaxMsgSize = 10 * 1024 * 1024
	NetworkId          = 3
)
View Source
const (
	Low    = iota // 0
	Medium        // 1
	High          // 2

)

priorities

View Source
const (
	DeliverReq   = iota // 0
	PushReq             // 1
	PropagateReq        // 2
	HistoryReq          // 3
	BacklogReq          // 4
)

request types

Variables

This section is empty.

Functions

func Bzz

func Bzz(cloud StorageHandler, backend chequebook.Backend, hive *Hive, dbaccess *DbAccess, sp *bzzswap.SwapParams, sy *SyncParams, networkId uint64) (p2p.Protocol, error)

main entrypoint, wrappers starting a server that will run the bzz protocol use this constructor to attach the protocol ("class") to server caps This is done by node.Node#Register(func(node.ServiceContext) (Service, error)) Service implements Protocols() which is an array of protocol constructors at node startup the protocols are initialised the Dev p2p layer then calls Run(p *p2p.Peer, rw p2p.MsgReadWriter) error on each peer connection The Run function of the Bzz protocol class creates a bzz instance which will represent the peer for the swarm hive and all peer-aware components

func Deliver

func Deliver(p *peer, req interface{}, ty int)

initiate delivery of a chunk to a particular peer via syncer#addRequest depending on syncer mode and priority settings and sync request type this either goes via confirmation roundtrip or queued or pushed directly

func NewForwarder

func NewForwarder(hive *Hive) *forwarder

func Push

func Push(p *peer, key storage.Key, priority uint)

push chunk over to peer

Types

type DbAccess

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

wrapper of db-s to provide mockable custom local chunk store access to syncer

func NewDbAccess

func NewDbAccess(loc *storage.LocalStore) *DbAccess

type Depo

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

Handler for storage/retrieval related protocol requests implements the StorageHandler interface used by the bzz protocol

func NewDepo

func NewDepo(hash storage.SwarmHasher, localStore, remoteStore storage.ChunkStore) *Depo

func (*Depo) HandleDeliveryRequestMsg

func (self *Depo) HandleDeliveryRequestMsg(req *deliveryRequestMsgData, p *peer) error

Handles deliveryRequestMsg * serves actual chunks asked by the remote peer by pushing to the delivery queue (sync db) of the correct priority (remote peer is free to reprioritize) * the message implies remote peer wants more, so trigger for * new outgoing unsynced keys message is fired

func (*Depo) HandleRetrieveRequestMsg

func (self *Depo) HandleRetrieveRequestMsg(req *retrieveRequestMsgData, p *peer)

entrypoint for retrieve requests coming from the bzz wire protocol checks swap balance - return if peer has no credit

func (*Depo) HandleStoreRequestMsg

func (self *Depo) HandleStoreRequestMsg(req *storeRequestMsgData, p *peer)

the entrypoint for store requests coming from the bzz wire protocol if key found locally, return. otherwise remote is untrusted, so hash is verified and chunk passed on to NetStore

func (*Depo) HandleUnsyncedKeysMsg

func (self *Depo) HandleUnsyncedKeysMsg(req *unsyncedKeysMsgData, p *peer) error

Handles UnsyncedKeysMsg after msg decoding - unsynced hashes upto sync state * the remote sync state is just stored and handled in protocol * filters through the new syncRequests and send the ones missing * back immediately as a deliveryRequest message * empty message just pings back for more (is this needed?) * strict signed sync states may be needed.

type Hive

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

func NewHive

func NewHive(addr common.Hash, params *HiveParams, swapEnabled, syncEnabled bool) *Hive

func (*Hive) Addr

func (self *Hive) Addr() kademlia.Address

public accessor to the hive base address

func (*Hive) BlockNetworkRead

func (self *Hive) BlockNetworkRead(on bool)

func (*Hive) BlockNetworkWrite

func (self *Hive) BlockNetworkWrite(on bool)

func (*Hive) DropAll

func (self *Hive) DropAll()

disconnects all the peers

func (*Hive) HandlePeersMsg

func (self *Hive) HandlePeersMsg(req *peersMsgData, from *peer)

called by the protocol when receiving peerset (for target address) peersMsgData is converted to a slice of NodeRecords for Kademlia this is to store all thats needed

func (*Hive) Start

func (self *Hive) Start(id discover.NodeID, listenAddr func() string, connectPeer func(string) error) (err error)

Start receives network info only at startup listedAddr is a function to retrieve listening address to advertise to peers connectPeer is a function to connect to a peer based on its NodeID or enode URL there are called on the p2p.Server which runs on the node

func (*Hive) Stop

func (self *Hive) Stop() error

func (*Hive) String

func (self *Hive) String() string

func (*Hive) SwapEnabled

func (self *Hive) SwapEnabled(on bool)

func (*Hive) SyncEnabled

func (self *Hive) SyncEnabled(on bool)

type HiveParams

type HiveParams struct {
	CallInterval uint64
	KadDbPath    string
	*kademlia.KadParams
}

func NewDefaultHiveParams added in v1.8.0

func NewDefaultHiveParams() *HiveParams

create default params

func (*HiveParams) Init added in v1.8.0

func (self *HiveParams) Init(path string)

this can only finally be set after all config options (file, cmd line, env vars) have been evaluated

type StorageHandler

type StorageHandler interface {
	HandleUnsyncedKeysMsg(req *unsyncedKeysMsgData, p *peer) error
	HandleDeliveryRequestMsg(req *deliveryRequestMsgData, p *peer) error
	HandleStoreRequestMsg(req *storeRequestMsgData, p *peer)
	HandleRetrieveRequestMsg(req *retrieveRequestMsgData, p *peer)
}

interface type for handler of storage/retrieval related requests coming via the bzz wire protocol messages: UnsyncedKeys, DeliveryRequest, StoreRequest, RetrieveRequest

type SyncParams

type SyncParams struct {
	RequestDbPath      string // path for request db (leveldb)
	RequestDbBatchSize uint   // nuber of items before batch is saved to requestdb
	KeyBufferSize      uint   // size of key buffer
	SyncBatchSize      uint   // maximum batchsize for outgoing requests
	SyncBufferSize     uint   // size of buffer for
	SyncCacheSize      uint   // cache capacity to store request queue in memory
	SyncPriorities     []uint // list of priority levels for req types 0-3
	SyncModes          []bool // list of sync modes for  for req types 0-3
}

syncer parameters (global, not peer specific)

func NewDefaultSyncParams added in v1.8.0

func NewDefaultSyncParams() *SyncParams

constructor with default values

func (*SyncParams) Init added in v1.8.0

func (self *SyncParams) Init(path string)

this can only finally be set after all config options (file, cmd line, env vars) have been evaluated

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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