network

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncBlock        = "SyncBlock"
	SyncPeerList     = "SyncPeerList"
	RequestBlock     = "requestBlock"
	BroadcastTx      = "BroadcastTx"
	TestMsgRadiation = "TestMsgRadiation"
)

Variables

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

Functions

This section is empty.

Types

type Dapmsg

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

func NewDapmsg

func NewDapmsg(cmd string, data []byte) *Dapmsg

func (*Dapmsg) FromProto

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

func (*Dapmsg) GetCmd

func (dm *Dapmsg) GetCmd() string

func (*Dapmsg) GetData

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

func (*Dapmsg) GetTimestamp

func (dm *Dapmsg) GetTimestamp() int64

func (*Dapmsg) ToProto

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

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

func (*Node) GetBlockchain

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

func (*Node) GetBlocks

func (n *Node) GetBlocks() []*core.Block

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

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

func (*Node) SendBlock

func (n *Node) SendBlock(block *core.Block) 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) SyncPeers

func (n *Node) SyncPeers() 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) 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