p2p

package
v3.8.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2020 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PEER_STATE_INIT      = 1
	PEER_STATE_HANDSHAKE = 2
)

DO NOT EDIT

View Source
const (
	MAX_PACKET_LEN = 10000000
)

DO NOT EDIT

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicPeerInfo

type BasicPeerInfo struct {
	ChainId string
}

BasicPeerInfo define struct for PeerInfo signature

var BasicLocalPeerInfo BasicPeerInfo

BasicLocalPeerInfo

func (*BasicPeerInfo) Hash

func (pi *BasicPeerInfo) Hash() common.Hash

Hash BasicPeerInfo hash

type BcastMsgPacket

type BcastMsgPacket struct {
	Indexs []uint16
	P      Packet
}

BcastMsgPacket it is a multicast packet , Indexs is filter peers index which not send to

type Head struct {
	ProtocolType uint16
	PacketType   uint16
	Pad          uint16
}

Head packet head

type NewconnCb

type NewconnCb func(conn net.Conn)

NewconnCb create a new candidate instance when accept a connection

type P2PServer

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

P2PServer p2p server

var Runner *P2PServer

Runner p2p global instance

func MakeP2PServer

func MakeP2PServer(p *config.P2PConfig, roleIntf role.RoleInterface) *P2PServer

MakeP2PServer create instance

func (*P2PServer) AddPeer

func (s *P2PServer) AddPeer(peer *Peer) error

AddPeer add a peer

func (*P2PServer) DelPeer

func (s *P2PServer) DelPeer(index uint16) bool

DelPeer delete a peer by index

func (*P2PServer) GetPeer

func (s *P2PServer) GetPeer(index uint16) *PeerInfo

GetPeer get a peer by index

func (*P2PServer) GetPeerP2PInfo

func (s *P2PServer) GetPeerP2PInfo() []Peer

GetPeerP2P get all peers

func (*P2PServer) GetPeers

func (s *P2PServer) GetPeers() []PeerInfo

GetPeers get all peers

func (*P2PServer) GetPeersData

func (s *P2PServer) GetPeersData() PeerDataSet

GetPeersData get a peer's info

func (*P2PServer) IsPeerExist

func (s *P2PServer) IsPeerExist(index uint16) bool

IsPeerExist judege if a peer exist or not by index

func (*P2PServer) IsPeerInfoExist

func (s *P2PServer) IsPeerInfoExist(info PeerInfo) bool

IsPeerInfoExist judge if a peer exist or not by peer info

func (*P2PServer) SendBroadcast

func (s *P2PServer) SendBroadcast(packet BcastMsgPacket)

SendBroadcast send a packet to some peer which is not set filter

func (*P2PServer) SendUnicast

func (s *P2PServer) SendUnicast(packet UniMsgPacket)

SendUnicast send a packet to a peer

func (*P2PServer) SetCallback

func (s *P2PServer) SetCallback(conn NewconnCb)

SetCallback set new connection call back

func (*P2PServer) Start

func (s *P2PServer) Start()

Start start p2p

type Packet

type Packet struct {
	H    Head
	Data []byte
}

Packet packet

type Peer

type Peer struct {
	Info  PeerInfo
	Index uint16

	/*peer state*/
	State int

	In bool
	// contains filtered or unexported fields
}

Peer peer...

func CreatePeer

func CreatePeer(info PeerInfo, conn net.Conn, in bool, sendup SendupCb) *Peer

CreatePeer create a instance

func (*Peer) Send

func (p *Peer) Send(packet Packet) error

Send send a packet

func (*Peer) Start

func (p *Peer) Start()

Start start peer routine

func (*Peer) Stop

func (p *Peer) Stop()

Stop stop peer net conn

type PeerData

type PeerData struct {
	Id    string
	Index uint16
}

PeerData peer's key info

type PeerDataSet

type PeerDataSet []PeerData

PeerDataSet peer's key info slice

func (PeerDataSet) Len

func (s PeerDataSet) Len() int

Len length

func (PeerDataSet) Less

func (s PeerDataSet) Less(i, j int) bool

Less small or not

func (PeerDataSet) Swap

func (s PeerDataSet) Swap(i, j int)

Swap swap

type PeerInfo

type PeerInfo struct {
	//Id peer id
	Id string
	//Addr peer address
	Addr string
	//Port peer port
	Port string
	//ChainId peer work chain id
	ChainId string
	//Signature peer auth
	Signature []byte
	//Version
	Version uint32
}

PeerInfo peer's info

var LocalPeerInfo PeerInfo

LocalPeerInfo ourself node info

func (*PeerInfo) Bigger

func (a *PeerInfo) Bigger(b PeerInfo) int

Bigger 1 a > b; 0 a = b ; -1 a < b

func (*PeerInfo) Equal

func (a *PeerInfo) Equal(b PeerInfo) bool

Equal peer's info compare

func (*PeerInfo) Hash

func (pi *PeerInfo) Hash() common.Hash

Hash PeerInfo hash

func (*PeerInfo) IsIncomplete

func (a *PeerInfo) IsIncomplete() bool

IsIncomplete judege peer's info is complete or not

func (*PeerInfo) Sign

func (pi *PeerInfo) Sign(bp BasicPeerInfo, privkey []byte) ([]byte, error)

Sign sign a PeerInfo with privkey

type SendupCb

type SendupCb func(index uint16, p *Packet)

SendupCb send up callback when receive a packet

type UniMsgPacket

type UniMsgPacket struct {
	Index uint16
	P     Packet
}

UniMsgPacket it is a unicast packet , Index is peer id to send to

Jump to

Keyboard shortcuts

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