network

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: LGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncBlock    = "SyncBlock"
	SyncPeerList = "SyncPeerList"
	RequestBlock = "requestBlock"
	BroadcastTx  = "BroadcastTx"
	Unicast      = 0
	Broadcast    = 1
)
View Source
const (
	MaxMsgCountBeforeReset = 999999
)

Variables

View Source
var (
	ErrDapMsgNoCmd  = errors.New("ERROR: Dappley message has no command input")
	ErrIsInPeerlist = errors.New("ERROR: Peer already exists in peerlist")
)
View Source
var (
	ErrInvalidMessageFormat = errors.New("Message format is invalid")
)
View Source
var PEERLISTMAXSIZE = 20

Functions

This section is empty.

Types

type DapMsg added in v0.1.1

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

func NewDapmsg

func NewDapmsg(cmd string, data []byte, msgKey string, uniOrBroadcast int, counter *uint64) *DapMsg

func (*DapMsg) FromProto added in v0.1.1

func (dm *DapMsg) FromProto(pb proto.Message)

func (*DapMsg) GetCmd added in v0.1.1

func (dm *DapMsg) GetCmd() string

func (*DapMsg) GetData added in v0.1.1

func (dm *DapMsg) GetData() []byte

func (*DapMsg) GetFrom added in v0.1.1

func (dm *DapMsg) GetFrom() string

func (*DapMsg) GetKey added in v0.1.1

func (dm *DapMsg) GetKey() string

used to lookup dapmsg cache (key:unix time of command + command in string, value: 1 if received recently, 0 if not).

func (*DapMsg) GetTimestamp added in v0.1.1

func (dm *DapMsg) GetTimestamp() int64

func (*DapMsg) ToProto added in v0.1.1

func (dm *DapMsg) ToProto() proto.Message

type Node

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

func FakeNodeWithPeer

func FakeNodeWithPeer(pid, addr string) *Node

func FakeNodeWithPidAndAddr added in v0.1.1

func FakeNodeWithPidAndAddr(bc *core.Blockchain, pid, addr string) *Node

func NewNode

func NewNode(bc *core.Blockchain) *Node

create new Node instance

func (*Node) AddStream

func (n *Node) AddStream(peerid peer.ID, targetAddr ma.Multiaddr) error

func (*Node) AddStreamByString

func (n *Node) AddStreamByString(targetFullAddr string) error

func (*Node) AddStreamMultiAddr

func (n *Node) AddStreamMultiAddr(targetFullAddr ma.Multiaddr) error

AddStreamMultiAddr stream to the targetFullAddr address. If the targetFullAddr is nil, the node goes to listening mode

func (*Node) BroadcastBlock added in v0.1.2

func (n *Node) BroadcastBlock(block *core.Block) error

func (*Node) BroadcastTxCmd

func (n *Node) BroadcastTxCmd(txn *core.Transaction) error

func (*Node) GetBlockchain

func (n *Node) GetBlockchain() *core.Blockchain

func (*Node) GetInfo

func (n *Node) GetInfo() *Peer

func (*Node) GetPeerID

func (n *Node) GetPeerID() peer.ID

func (*Node) GetPeerList

func (n *Node) GetPeerList() *PeerList

func (*Node) GetPeerMultiaddr

func (n *Node) GetPeerMultiaddr() ma.Multiaddr

func (*Node) GetRecentlyRcvedDapMsgs added in v0.1.1

func (n *Node) GetRecentlyRcvedDapMsgs() *sync.Map

func (*Node) LoadNetworkKeyFromFile added in v0.1.2

func (n *Node) LoadNetworkKeyFromFile(filePath string) error

LoadNetworkKeyFromFile reads the network privatekey from a file

func (*Node) RelayDapMsg added in v0.1.1

func (n *Node) RelayDapMsg(dm DapMsg)

func (*Node) RequestBlockUnicast

func (n *Node) RequestBlockUnicast(hash core.Hash, pid peer.ID) error

func (*Node) SendBlockUnicast

func (n *Node) SendBlockUnicast(block *core.Block, pid peer.ID) error

func (*Node) Start

func (n *Node) Start(listenPort int) error

func (*Node) StartRequestLoop

func (n *Node) StartRequestLoop()

func (*Node) SyncPeersBroadcast added in v0.1.2

func (n *Node) SyncPeersBroadcast() error

func (*Node) SyncPeersUnicast added in v0.1.1

func (n *Node) SyncPeersUnicast(pid peer.ID) error

func (*Node) TxBroadcast added in v0.1.2

func (n *Node) TxBroadcast(tx *core.Transaction) error

type Peer

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

func CreatePeerFromMultiaddr

func CreatePeerFromMultiaddr(targetFullAddr multiaddr.Multiaddr) (*Peer, error)

func CreatePeerFromString

func CreatePeerFromString(targetFullAddr string) (*Peer, error)

func (*Peer) FromProto

func (p *Peer) FromProto(pb proto.Message) error

convert from protobuf

func (*Peer) ToProto

func (p *Peer) ToProto() proto.Message

convert to protobuf

type PeerList

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

func NewPeerList

func NewPeerList(p []*Peer) *PeerList

create new peerList with multiaddress

func NewPeerListStr

func NewPeerListStr(strs []string) *PeerList

create new peerList with strings

func (*PeerList) Add

func (pl *PeerList) Add(p *Peer)

Add a multiadress.

func (*PeerList) AddMultiple

func (pl *PeerList) AddMultiple(ps []*Peer)

add multiple addresses

func (*PeerList) DeletePeer added in v0.1.2

func (pl *PeerList) DeletePeer(p *Peer)

func (*PeerList) FindNewPeers

func (pl *PeerList) FindNewPeers(newpl *PeerList) *PeerList

find the peers in newpl that are not contained in current pl

func (*PeerList) FromProto

func (pl *PeerList) FromProto(pb proto.Message)

convert from protobuf

func (*PeerList) GetPeerlist

func (pl *PeerList) GetPeerlist() []*Peer

Get peerList

func (*PeerList) IsInPeerlist

func (pl *PeerList) IsInPeerlist(p *Peer) bool

Check if a multiaddress is already existed in the list

func (*PeerList) ListIsFull

func (pl *PeerList) ListIsFull() bool

func (*PeerList) MergePeerlist

func (pl *PeerList) MergePeerlist(newpl *PeerList)

merge two peerlists

func (*PeerList) RemoveOneIP

func (pl *PeerList) RemoveOneIP(p *Peer)

remove old ip give space for new ip

func (*PeerList) ToProto

func (pl *PeerList) ToProto() proto.Message

convert to protobuf

type Stream

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

func NewStream

func NewStream(s net.Stream, node *Node) *Stream

func (*Stream) Send

func (s *Stream) Send(data []byte)

func (*Stream) Start

func (s *Stream) Start()

func (*Stream) StopStream

func (s *Stream) StopStream()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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