netserver

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNetServer

func NewNetServer(ctx *node.ServiceContext, lg *logrus.Logger) p2p.P2P

NewNetServer return the net object in p2p

func TLSDial

func TLSDial(nodeAddr, CertPath, KeyPath, CAPath string) (net.Conn, error)

TLSDial return net.Conn with TLS

Types

type ConnectingNodes

type ConnectingNodes struct {
	sync.RWMutex
	ConnectingAddrs []string
}

ConnectingNodes include all addr in connecting state

type InConnectionRecord

type InConnectionRecord struct {
	sync.RWMutex
	InConnectingAddrs []string
}

InConnectionRecord include all addr connected

type NetServer

type NetServer struct {
	SyncChan chan *types.MsgPayload
	ConsChan chan *types.MsgPayload
	ConnectingNodes
	PeerAddrMap
	Np *peer.NbrPeers

	OwnAddress   string //network`s own address(ip : sync port),which get from version check
	NetworkMagic uint32
	// contains filtered or unexported fields
}

NetServer represent all the actions in net layer

func (*NetServer) AddInConnRecord

func (this *NetServer) AddInConnRecord(addr string)

AddInConnRecord add in connection to inConnRecord

func (*NetServer) AddNbrNode

func (this *NetServer) AddNbrNode(remotePeer *peer.Peer)

AddNbrNode add peer to nbr peer list

func (*NetServer) AddOutConnRecord

func (this *NetServer) AddOutConnRecord(addr string)

AddOutConnRecord add out connection to outConnRecord

func (*NetServer) AddOutConnectingList

func (this *NetServer) AddOutConnectingList(addr string) (added bool)

record the peer which is going to be dialed and sent version message but not in establish state

func (*NetServer) AddPeerConsAddress

func (this *NetServer) AddPeerConsAddress(addr string, p *peer.Peer)

AddPeerConsAddress add cons addr to peer-addr map

func (*NetServer) AddPeerSyncAddress

func (this *NetServer) AddPeerSyncAddress(addr string, p *peer.Peer)

AddPeerSyncAddress add sync addr to peer-addr map

func (*NetServer) AddrValid

func (this *NetServer) AddrValid(addr string) bool

AddrValid whether the addr could be connect or accept

func (*NetServer) Broadcast

func (this *NetServer) Broadcast(msg types.Message, isConsensus bool)

func (*NetServer) CheckStartUpFinished added in v1.0.2

func (this *NetServer) CheckStartUpFinished() bool

func (*NetServer) Connect

func (this *NetServer) Connect(addr string, isConsensus bool) error

Connect used to connect net address under sync or cons mode

func (*NetServer) DelNbrNode

func (this *NetServer) DelNbrNode(p *peer.Peer) (*peer.Peer, bool)

DelNbrNode delete nbr peer

func (*NetServer) GetConnectionCnt

func (this *NetServer) GetConnectionCnt() uint32

GetConnectionCnt return the total number of valid connections

func (*NetServer) GetConsPort

func (this *NetServer) GetConsPort() uint32

GetConsPort return the cons port

func (*NetServer) GetContex added in v1.0.2

func (this *NetServer) GetContex() *node.ServiceContext

func (*NetServer) GetHeight

func (this *NetServer) GetHeight() uint64

GetHeight return peer's heigh

func (*NetServer) GetID

func (this *NetServer) GetID() uint64

GetId return peer`s id

func (*NetServer) GetInConnRecordLen

func (this *NetServer) GetInConnRecordLen() int

GetInConnRecordLen return length of inConnRecordList

func (*NetServer) GetIpCountInInConnRecord

func (this *NetServer) GetIpCountInInConnRecord(ip string) uint

GetIpCountInInConnRecord return count of in connections with single ip

func (*NetServer) GetLog added in v1.0.2

func (this *NetServer) GetLog() *logrus.Logger

func (*NetServer) GetMagic added in v1.0.2

func (this *NetServer) GetMagic() uint32

func (*NetServer) GetMsgChan

func (this *NetServer) GetMsgChan(isConsensus bool) chan *types.MsgPayload

GetMsgChan return sync or consensus channel when msgrouter need msg input

func (*NetServer) GetNeighborAddrs

func (this *NetServer) GetNeighborAddrs() []*types.PeerAddr

GetNeighborAddrs return all the nbr peer`s addr

func (*NetServer) GetNeighbors

func (this *NetServer) GetNeighbors() []*peer.Peer

GetNeighbors return all nbr peer

func (*NetServer) GetNp

func (this *NetServer) GetNp() *peer.NbrPeers

return nbr peers collection

func (*NetServer) GetOutConnRecordLen

func (this *NetServer) GetOutConnRecordLen() int

GetOutConnRecordLen return length of outConnRecord

func (*NetServer) GetOutConnectingListLen

func (this *NetServer) GetOutConnectingListLen() (count uint)

record the peer which is going to be dialed and sent version message but not in establish state

func (*NetServer) GetPeer

func (this *NetServer) GetPeer(id uint64) *peer.Peer

GetPeer returns a peer with the peer id

func (*NetServer) GetPeerFromAddr

func (this *NetServer) GetPeerFromAddr(addr string) *peer.Peer

find exist peer from addr map

func (*NetServer) GetPeerSyncAddressCount

func (this *NetServer) GetPeerSyncAddressCount() (count uint)

GetPeerSyncAddressCount return length of cons addr from peer-addr map

func (*NetServer) GetRelay

func (this *NetServer) GetRelay() bool

GetRelay return whether net module can relay msg

func (*NetServer) GetService

func (this *NetServer) GetService(str string) (interface{}, error)

func (*NetServer) GetServices

func (this *NetServer) GetServices() uint64

GetServices return the service state of self peer

func (*NetServer) GetSyncPort

func (this *NetServer) GetSyncPort() uint32

GetSyncPort return the sync port

func (*NetServer) GetTime

func (this *NetServer) GetTime() int64

GetTime return the last contact time of self peer

func (*NetServer) GetVersion

func (this *NetServer) GetVersion() uint32

GetVersion return self peer`s version

func (*NetServer) Halt

func (this *NetServer) Halt()

Halt stop all net layer logic

func (*NetServer) IsAddrFromConnecting

func (this *NetServer) IsAddrFromConnecting(addr string) bool

check peer from connecting list

func (*NetServer) IsAddrInInConnRecord

func (this *NetServer) IsAddrInInConnRecord(addr string) bool

IsAddrInInConnRecord return result whether addr is in inConnRecordList

func (*NetServer) IsAddrInOutConnRecord

func (this *NetServer) IsAddrInOutConnRecord(addr string) bool

IsAddrInOutConnRecord return result whether addr is in outConnRecord

func (*NetServer) IsIPInInConnRecord

func (this *NetServer) IsIPInInConnRecord(ip string) bool

IsIPInInConnRecord return result whether the IP is in inConnRecordList

func (*NetServer) IsNbrPeerAddr

func (this *NetServer) IsNbrPeerAddr(addr string, isConsensus bool) bool

IsNbrPeerAddr return result whether the address is under connecting

func (*NetServer) IsOwnAddress

func (this *NetServer) IsOwnAddress(addr string) bool

check own network address

func (*NetServer) IsPeerEstablished

func (this *NetServer) IsPeerEstablished(p *peer.Peer) bool

IsPeerEstablished return the establise state of given peer`s id

func (*NetServer) NodeEstablished

func (this *NetServer) NodeEstablished(id uint64) bool

NodeEstablished return whether a peer is establish with self according to id

func (*NetServer) RememberMsg added in v1.0.2

func (this *NetServer) RememberMsg(hash [common.HashSize]byte) bool

func (*NetServer) RemoveFromConnectingList

func (this *NetServer) RemoveFromConnectingList(addr string)

Remove the peer from connecting list if the connection is established

func (*NetServer) RemoveFromInConnRecord

func (this *NetServer) RemoveFromInConnRecord(addr string)

RemoveInConnRecord remove in connection from inConnRecordList

func (*NetServer) RemoveFromOutConnRecord

func (this *NetServer) RemoveFromOutConnRecord(addr string)

RemoveOutConnRecord remove out connection from outConnRecord

func (*NetServer) RemovePeerConsAddress

func (this *NetServer) RemovePeerConsAddress(addr string)

RemovePeerConsAddress remove cons addr from peer-addr map

func (*NetServer) RemovePeerSyncAddress

func (this *NetServer) RemovePeerSyncAddress(addr string)

RemovePeerSyncAddress remove sync addr from peer-addr map

func (*NetServer) Send

func (this *NetServer) Send(p *peer.Peer, msg types.Message, isConsensus bool) error

Tx send data buf to peer

func (*NetServer) SetHeight

func (this *NetServer) SetHeight(height uint64)

SetHeight sets the local's height

func (*NetServer) SetOwnAddress

func (this *NetServer) SetOwnAddress(addr string)

Set own network address

func (*NetServer) Start

func (this *NetServer) Start()

InitListen start listening on the config port

type OutConnectionRecord

type OutConnectionRecord struct {
	sync.RWMutex
	OutConnectingAddrs []string
}

OutConnectionRecord include all addr accepted

type PeerAddrMap

type PeerAddrMap struct {
	sync.RWMutex
	PeerSyncAddress map[string]*peer.Peer
	PeerConsAddress map[string]*peer.Peer
}

PeerAddrMap include all addr-peer list

Jump to

Keyboard shortcuts

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