p2p

package
v0.0.0-...-25c57ca Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2018 License: BSD-2-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxInventoryTickleSize = 1000
	StallResponseTimeout   = 30 * time.Second
	StallTickInterval      = 15 * time.Second
	IdleTimeout            = 5 * time.Minute
	TrickleTimeout         = 10 * time.Second
	PingInterval           = 2 * time.Minute
	NegotiateTimeOut       = 30 * time.Second
	OutPutBufferSize       = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockManager

type BlockManager struct {
	Chain *model.BlockChain
	// contains filtered or unexported fields
}

func (*BlockManager) NewPeer

func (blockManager *BlockManager) NewPeer(serverPeer *ServerPeer)

func (*BlockManager) Start

func (blockManager *BlockManager) Start()

func (*BlockManager) Stop

func (blockManager *BlockManager) Stop()

type BlockProgressLogger

type BlockProgressLogger struct {
	LastBlockLogTime time.Time
	// contains filtered or unexported fields
}

func (*BlockProgressLogger) LogBlockHeight

func (blockLog *BlockProgressLogger) LogBlockHeight(block *model.Block)

type BroadcastMessage

type BroadcastMessage struct {
	Message      *msg.Message
	ExcludePeers []*ServerPeer
}

type MessageListener

type MessageListener struct {
	OnRead  func(p *Peer, bytesRead int, message msg.Message, err error)
	OnWrite func(p *Peer, bytesWritten int, message msg.Message, err error)

	OnVersion func(p *Peer, versionMessage *msg.VersionMessage)
	OnGetAddr func(p *Peer, msg *msg.GetAddressMessage)
	OnAddr    func(p *Peer, msg *msg.AddressMessage)

	OnPing func(p *Peer, msg *msg.PingMessage)
	OnPong func(p *Peer, msg *msg.PongMessage)

	OnAlert func(p *Peer, msg *msg.AlertMessage)

	OnMemPool func(p *Peer, msg *msg.MempoolMessage)
	OnTx      func(p *Peer, msg *msg.TxMessage)
	OnBlock   func(p *Peer, msg *msg.BlockMessage, buf []byte)

	OnInv func(p *Peer, msg *msg.InventoryMessage)

	OnHeaders  func(p *Peer, msg *msg.HeadersMessage)
	OnNotFound func(p *Peer, msg *msg.NotFoundMessage)

	OnGetData func(p *Peer, msg *msg.GetDataMessage)

	OnGetBlocks  func(p *Peer, msg *msg.GetBlocksMessage)
	OnGetHeaders func(p *Peer, msg *msg.GetHeadersMessage)

	OnFilterAdd   func(p *Peer, msg *msg.FilterAddMessage)
	OnFilterClear func(p *Peer, msg *msg.FilterClearMessage)
	OnFilterLoad  func(p *Peer, msg *msg.FilterLoadMessage)
	OnMerkleBlock func(p *Peer, msg *msg.MerkleBlockMessage)

	OnVerAck      func(p *Peer, msg *msg.VersionACKMessage)
	OnReject      func(p *Peer, msg msg.RejectMessage)
	OnSendHeaders func(p *Peer, msg *msg.SendHeadersMessage)
}

type NewPeerMessage

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

type Peer

type Peer struct {
	Config *PeerConfig
	ID     int32

	Inbound          bool
	BlockStatusMutex sync.RWMutex

	AddressString string

	PeerStatusMutex sync.RWMutex
	PeerAddress     *network.PeerAddress
	ServiceFlag     protocol.ServiceFlag

	UserAgent    string
	PingNonce    uint64
	PingTime     time.Time
	PingMicros   int64
	VersionKnown bool
	SentVerAck   bool
	GotVerAck    bool

	StallControl chan StallControlMessage

	ProtocolVersion      uint32
	LastBlock            int32
	ConnectedTime        time.Time
	TimeOffset           int64
	StartingHeight       int32
	SendHeadersPreferred bool
	OutputQueue          chan msg.OutMessage
	SendQueue            chan msg.OutMessage

	GetBlocksLock  sync.Mutex
	GetBlocksBegin *utils.Hash
	GetBlocksStop  *utils.Hash

	GetHeadersLock  sync.Mutex
	GetHeadersBegin *utils.Hash
	GetHeadersStop  *utils.Hash
	// contains filtered or unexported fields
}

func NewInboundPeer

func NewInboundPeer(peerConfig *PeerConfig) *Peer

func NewOutboundPeer

func NewOutboundPeer(peerConfig *PeerConfig, addressString string) (*Peer, error)

func (*Peer) Connect

func (p *Peer) Connect(conn net.Conn)

func (*Peer) Connected

func (p *Peer) Connected() bool

func (*Peer) Disconnect

func (p *Peer) Disconnect()

func (*Peer) GetLastDeclareBlock

func (p *Peer) GetLastDeclareBlock() *utils.Hash

func (*Peer) GetNetAddress

func (p *Peer) GetNetAddress() *network.PeerAddress

func (*Peer) GetPeerID

func (p *Peer) GetPeerID() int32

func (*Peer) GetServiceFlag

func (p *Peer) GetServiceFlag() protocol.ServiceFlag

func (*Peer) GetUserAgent

func (p *Peer) GetUserAgent() string

func (*Peer) HandlePingMessage

func (p *Peer) HandlePingMessage(pingMessage *msg.PingMessage)

func (*Peer) HandlePongMessage

func (p *Peer) HandlePongMessage(pongMessage *msg.PongMessage)

func (*Peer) HandleRemoteVersionMessage

func (p *Peer) HandleRemoteVersionMessage(versionMessage *msg.VersionMessage) error

func (*Peer) IsAllowedReadError

func (p *Peer) IsAllowedReadError(err error) bool

func (*Peer) IsValidBIP0111

func (p *Peer) IsValidBIP0111(command string) bool

func (*Peer) LastReceived

func (p *Peer) LastReceived() uint64

func (*Peer) LastSent

func (p *Peer) LastSent() uint64

func (*Peer) LocalVersionMsg

func (p *Peer) LocalVersionMsg() (*msg.VersionMessage, error)

func (*Peer) QueueInventory

func (p *Peer) QueueInventory(inventoryVector *msg.InventoryVector)

func (*Peer) ReadMessage

func (p *Peer) ReadMessage() (msg.Message, []byte, error)

func (*Peer) SendAddrMessage

func (p *Peer) SendAddrMessage(addresses []*network.PeerAddress) ([]*network.PeerAddress, error)

func (*Peer) SendGetBlocks

func (p *Peer) SendGetBlocks(locator []*utils.Hash, stopHash *utils.Hash) error

func (*Peer) SendGetHeadersMessage

func (p *Peer) SendGetHeadersMessage(locator []*utils.Hash, stopHash *utils.Hash) error

func (*Peer) SendMessage

func (p *Peer) SendMessage(message msg.Message, doneChan chan<- struct{})

func (*Peer) SendRejectMessage

func (p *Peer) SendRejectMessage(command string, code msg.RejectCode, reason string, hash *utils.Hash, wait bool)

func (*Peer) Stop

func (p *Peer) Stop()

func (*Peer) String

func (p *Peer) String() string

func (*Peer) UpdateBlockHeight

func (p *Peer) UpdateBlockHeight(newHeight int32)

func (*Peer) UpdateDeclareBlock

func (p *Peer) UpdateDeclareBlock(blackHash *utils.Hash)

func (*Peer) WaitForDisconnect

func (p *Peer) WaitForDisconnect()

func (*Peer) WriteMessage

func (p *Peer) WriteMessage(message msg.Message) error

type PeerConfig

type PeerConfig struct {
	NewBlock          utils.HashFunc
	HostToAddressFunc network.HostToNetAddrFunc
	BestAddress       network.PeerAddressFunc

	Proxy            string
	UserAgent        string
	UserAgentVersion string

	// BIP 14
	UserAgentComments []string

	ServicesFlag    protocol.ServiceFlag
	ProtocolVersion uint32
	DisableRelayTx  bool
	Listener        MessageListener
	ChainParams     *msg.BitcoinParams
}

type PeerManager

type PeerManager struct {
	BlockManager *BlockManager
	// contains filtered or unexported fields
}

func NewPeerManager

func NewPeerManager(listenAddrs []string, storage storage.Storage, bitcoinParam *msg.BitcoinParams) (*PeerManager, error)

func (*PeerManager) AddPeer

func (peerManager *PeerManager) AddPeer(serverPeer *ServerPeer)

func (*PeerManager) BanPeer

func (peerManager *PeerManager) BanPeer(serverPeer *ServerPeer)

func (*PeerManager) OutboundGroupCount

func (peerManager *PeerManager) OutboundGroupCount(key string) int

func (*PeerManager) Start

func (peerManager *PeerManager) Start()

func (*PeerManager) Stop

func (peerManager *PeerManager) Stop() error

func (*PeerManager) WaitForShutdown

func (peerManager *PeerManager) WaitForShutdown()

type PeerState

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

func (*PeerState) Count

func (peerState *PeerState) Count() int

type RelayMessage

type RelayMessage struct {
	InventoryVector *msg.InventoryVector
	Data            interface{}
}

type ServerPeer

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

func NewServerPeer

func NewServerPeer(peerManager *PeerManager, isPersistent bool) *ServerPeer

func (*ServerPeer) OnAddr

func (serverPeer *ServerPeer) OnAddr(p *Peer, msg *msg.AddressMessage)

func (*ServerPeer) OnAlert

func (serverPeer *ServerPeer) OnAlert(p *Peer, msg *msg.AlertMessage)

func (*ServerPeer) OnBlock

func (serverPeer *ServerPeer) OnBlock(p *Peer, msg *msg.BlockMessage, buf []byte)

func (*ServerPeer) OnFilterAdd

func (serverPeer *ServerPeer) OnFilterAdd(p *Peer, msg *msg.FilterAddMessage)

func (*ServerPeer) OnFilterClear

func (serverPeer *ServerPeer) OnFilterClear(p *Peer, msg *msg.FilterClearMessage)

func (*ServerPeer) OnFilterLoad

func (serverPeer *ServerPeer) OnFilterLoad(p *Peer, msg *msg.FilterLoadMessage)

func (*ServerPeer) OnGetAddr

func (serverPeer *ServerPeer) OnGetAddr(p *Peer, msg *msg.GetAddressMessage)

func (*ServerPeer) OnGetBlocks

func (serverPeer *ServerPeer) OnGetBlocks(p *Peer, msg *msg.GetBlocksMessage)

func (*ServerPeer) OnGetData

func (serverPeer *ServerPeer) OnGetData(p *Peer, msg *msg.GetDataMessage)

func (*ServerPeer) OnGetHeaders

func (serverPeer *ServerPeer) OnGetHeaders(p *Peer, msg *msg.GetHeadersMessage)

func (*ServerPeer) OnHeaders

func (serverPeer *ServerPeer) OnHeaders(p *Peer, msg *msg.HeadersMessage)

func (*ServerPeer) OnInv

func (serverPeer *ServerPeer) OnInv(p *Peer, msg *msg.InventoryMessage)

func (*ServerPeer) OnMemPool

func (serverPeer *ServerPeer) OnMemPool(p *Peer, msg *msg.MempoolMessage)

func (*ServerPeer) OnMerkleBlock

func (serverPeer *ServerPeer) OnMerkleBlock(p *Peer, msg *msg.MerkleBlockMessage)

func (*ServerPeer) OnNotFound

func (serverPeer *ServerPeer) OnNotFound(p *Peer, msg *msg.NotFoundMessage)

func (*ServerPeer) OnPing

func (serverPeer *ServerPeer) OnPing(p *Peer, msg *msg.PingMessage)

func (*ServerPeer) OnPong

func (serverPeer *ServerPeer) OnPong(p *Peer, msg *msg.PongMessage)

func (*ServerPeer) OnRead

func (serverPeer *ServerPeer) OnRead(p *Peer, bytesRead int, message msg.Message, err error)

func (*ServerPeer) OnReject

func (serverPeer *ServerPeer) OnReject(p *Peer, msg msg.RejectMessage)

func (*ServerPeer) OnSendHeaders

func (serverPeer *ServerPeer) OnSendHeaders(p *Peer, msg *msg.SendHeadersMessage)

func (*ServerPeer) OnTx

func (serverPeer *ServerPeer) OnTx(p *Peer, msg *msg.TxMessage)

func (*ServerPeer) OnVerAck

func (serverPeer *ServerPeer) OnVerAck(p *Peer, msg *msg.VersionACKMessage)

func (*ServerPeer) OnVersion

func (serverPeer *ServerPeer) OnVersion(p *Peer, versionMessage *msg.VersionMessage)

func (*ServerPeer) OnWrite

func (serverPeer *ServerPeer) OnWrite(p *Peer, bytesWritten int, message msg.Message, err error)

func (*ServerPeer) RelayTxDisabled

func (serverPeer *ServerPeer) RelayTxDisabled() bool

func (*ServerPeer) SetDisableRelayTx

func (serverPeer *ServerPeer) SetDisableRelayTx(disable bool)

type StallControlCommand

type StallControlCommand uint8
const (
	SccSendMessage StallControlCommand = iota
	SccReceiveMessage
	SccHandlerStart
	SccHandlerDone
)

type StallControlMessage

type StallControlMessage struct {
	Command StallControlCommand
	Message msg.Message
}

type UpdatePeerHeightsMessage

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

Jump to

Keyboard shortcuts

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