Documentation ¶
Index ¶
- Constants
- Variables
- func AddNeighbor(neighborAddr string) error
- func AddProtocolHeader(buf *bytes.Buffer, protoMsgType ProtocolMsgType, payloadLengthBytes uint16) error
- func BroadcastTransaction(excludedNeighbors map[string]struct{}, truncatedTxData []byte, txHash []byte)
- func BroadcastTransactionFromAPI(txTrytes trinary.Trytes) error
- func Connect(neighbor *Neighbor) error
- func CreateHandshakePacket(ownSourcePort uint16, ownByteEncodedCooAddress []byte, ownUsedMWM byte) ([]byte, error)
- func CreateHeartbeatPacket(solidMilestoneIndex milestone_index.MilestoneIndex, ...) ([]byte, error)
- func CreateLegacyTransactionGossipPacket(truncatedTxData []byte, requestedHash []byte) ([]byte, error)
- func CreateMilestoneRequestPacket(requestedMilestoneIndex milestone_index.MilestoneIndex) ([]byte, error)
- func CreateTransactionGossipPacket(truncatedTxData []byte) ([]byte, error)
- func CreateTransactionRequestGossipPacket(requestedHash []byte) ([]byte, error)
- func DebugPrintQueueStats()
- func ExtractRequestedMilestoneIndex(source []byte) (milestone_index.MilestoneIndex, error)
- func ExtractRequestedTxHash(source []byte) []byte
- func GetConnectedNeighbors() map[string]*Neighbor
- func IsAddrBlacklisted(remoteAddr net.Addr) bool
- func NewNeighborIdentity(ip string, port uint16) string
- func ProcessReceivedLegacyTransactionGossipData(protocol *protocol, data []byte)
- func ProcessReceivedMilestoneRequest(protocol *protocol, data []byte)
- func ProcessReceivedTransactionGossipData(protocol *protocol, txData []byte)
- func ProcessReceivedTransactionRequestData(protocol *protocol, reqHash []byte)
- func RemoveNeighbor(originIdentity string) error
- func Request(hashes []trinary.Hash, reqMilestoneIndex milestone_index.MilestoneIndex)
- func RequestApprovees(tx *hornet.Transaction)
- func RequestMilestone(milestone *tangle.Bundle) bool
- func RequestMulti(hashes []trinary.Hash, reqMilestoneIndex milestone_index.MilestoneIndex)
- func SendHeartbeat()
- func SendMilestoneRequests(solidMilestoneIndex milestone_index.MilestoneIndex, ...)
- type ConnectionFailureError
- type ConnectionOrigin
- type Handshake
- type HandshakeError
- type HeaderState
- type Heartbeat
- type Neighbor
- func (n *Neighbor) IdentityOrAddress() string
- func (neighbor *Neighbor) Reply(recHashBytes []byte, neighborReq *NeighborRequest)
- func (neighbor *Neighbor) RequestLatestMilestone()
- func (neighbor *Neighbor) SendHeartbeat()
- func (neighbor *Neighbor) SendMilestoneRequest(msIndex milestone_index.MilestoneIndex)
- func (neighbor *Neighbor) SendTransactionRequest()
- func (n *Neighbor) SetProtocol(protocol *protocol)
- type NeighborConfig
- type NeighborInfo
- type NeighborRequest
- type PendingNeighborRequests
- func (p *PendingNeighborRequests) AddLegacyTxRequest(neighbor *protocol, reqHashBytes []byte)
- func (p *PendingNeighborRequests) BlockFeedback(neighbor *protocol)
- func (p *PendingNeighborRequests) GetTxHash() trinary.Hash
- func (p *PendingNeighborRequests) GetTxHashBytes() []byte
- func (p *PendingNeighborRequests) IsHashed() bool
- func (p *PendingNeighborRequests) IsHashing() bool
- func (p *PendingNeighborRequests) IsInvalid() bool
- type ProtocolHeader
- type ProtocolMessage
- type ProtocolMsgType
- type SendError
Constants ¶
const ( SEND_MS_REQ_QUEUE_SIZE = 1000 SEND_LEGACY_TX_QUEUE_SIZE = 1000 SEND_TX_QUEUE_SIZE = 1000 SEND_TX_REQ_SIZE = 1000 SEND_HEARTBEAT_SIZE = 1000 BROADCAST_QUEUE_SIZE = 1000 TX_TRYTES_SIZE = 2673 )
const ( PROTOCOL_VERSION_LEGACY_GOSSIP = 1 << 0 // STING supports sole transaction-, request-, milestone- and heartbeat messages PROTOCOL_VERSION_STING = 1 << 1 // The amount of bytes dedicated for the message type in the packet header. HEADER_TLV_TYPE_BYTES_LENGTH = 1 // The amount of bytes dedicated for the message length denotation in the packet header. HEADER_TLV_LENGTH_BYTES_LENGTH = 2 // The length of the TLV header HEADER_TLV_BYTES_LENGTH = 3 // The amount of bytes making up the protocol packet header. PROTOCOL_HEADER_BYTES_LENGTH = HEADER_TLV_LENGTH_BYTES_LENGTH + HEADER_TLV_TYPE_BYTES_LENGTH // The amount of bytes used for the requested transaction hash. GOSSIP_REQUESTED_TX_HASH_BYTES_LENGTH = 49 // The amount of bytes used for the requested milestone index. GOSSIP_REQUESTED_MS_INDEX_BYTES_LENGTH = 4 // The amount of bytes used for the a milestone index within a heartbeat packet. GOSSIP_HEARTBEAT_MS_INDEX_BYTES_LENGTH = 4 // The amount of bytes making up the non signature message fragment part of a transaction gossip payload. NON_SIG_TX_PART_BYTES_LENGTH = 292 // The max amount of bytes a signature message fragment is made up from. SIG_DATA_MAX_BYTES_LENGTH = 1312 PROTOCOL_MSG_TYPE_HEADER ProtocolMsgType = 0 PROTOCOL_MSG_TYPE_HANDSHAKE ProtocolMsgType = 1 PROTOCOL_MSG_TYPE_LEGACY_TX_GOSSIP ProtocolMsgType = 2 PROTOCOL_MSG_TYPE_MS_REQUEST ProtocolMsgType = 3 PROTOCOL_MSG_TYPE_TX_GOSSIP ProtocolMsgType = 4 PROTOCOL_MSG_TYPE_TX_REQ_GOSSIP ProtocolMsgType = 5 PROTOCOL_MSG_TYPE_HEARTBEAT ProtocolMsgType = 6 )
const ( VERSION_1 = byte(1) SIZE_HEADER = 3 )
const (
PACKET_PROCESSOR_WORKER_QUEUE_SIZE = 50000
)
Variables ¶
var ( ErrNeighborSlotsFilled = errors.New("neighbors slots filled") ErrNotMatchingMWM = errors.New("used MWM doesn't match") ErrNotMatchingCooAddr = errors.New("used coo addr doesn't match") ErrNotMatchingSrvSocketPort = errors.New("advertised server socket port doesn't match") ErrIdentityUnknown = errors.New("neighbor identity is not known") ErrNeighborAlreadyConnected = errors.New("neighbor is already connected") ErrNeighborAlreadyKnown = errors.New("neighbor is already known") // TODO: perhaps better naming ErrNoIPsFound = errors.New("didn't find any IPs") )
var ( RequestQueue *queue.RequestQueue IncomingCache *datastructure.LRUCache ErrTxExpired = errors.New("tx too old") )
var ( // Thrown when a packet advertises a message length which is invalid for the given {ProtocolMessage} type. ErrInvalidProtocolMessageType = errors.New("invalid protocol message type") ErrInvalidProtocolMessageLength = errors.New("invalid protocol message length") // Thrown when an unknown ProtocolMessage type is advertised in a packet. ErrUnknownMessageType = errors.New("unknown message type") // supports protocol version(s): 2+1 SUPPORTED_PROTOCOL_VERSIONS = []byte{PROTOCOL_VERSION_STING | PROTOCOL_VERSION_LEGACY_GOSSIP} // The message header sent in each message denoting the TLV fields. ProtocolHeaderMsg = ProtocolMessage{TypeID: PROTOCOL_MSG_TYPE_HEADER, MaxLength: PROTOCOL_HEADER_BYTES_LENGTH, SupportsDynamicLength: false} // The initial handshake packet sent over the wire up on a new neighbor connection. // Made up of: // - own server socket port (2 bytes) // - time at which the packet was sent (8 bytes) // - own used byte encoded coordinator address (49 bytes) // - own used MWM (1 byte) // - supported protocol versions. we need up to 32 bytes to represent 256 possible protocol // versions. only up to N bytes are used to communicate the highest supported version. ProtocolHandshakeMsg = ProtocolMessage{TypeID: PROTOCOL_MSG_TYPE_HANDSHAKE, MaxLength: 92, SupportsDynamicLength: true} // The transaction payload + requested transaction hash gossipping packet. In reality most of this packets won't // take up their full 1604 bytes as the signature message fragment of the tx is truncated. ProtocolLegacyTransactionGossipMsg = ProtocolMessage{TypeID: PROTOCOL_MSG_TYPE_LEGACY_TX_GOSSIP, MaxLength: GOSSIP_REQUESTED_TX_HASH_BYTES_LENGTH + NON_SIG_TX_PART_BYTES_LENGTH + SIG_DATA_MAX_BYTES_LENGTH, SupportsDynamicLength: true} // The transaction gossipping packet. Contains only a tx payload. ProtocolTransactionGossipMsg = ProtocolMessage{TypeID: PROTOCOL_MSG_TYPE_TX_GOSSIP, MaxLength: NON_SIG_TX_PART_BYTES_LENGTH + SIG_DATA_MAX_BYTES_LENGTH, SupportsDynamicLength: true} // The requested transaction hash gossipping packet. Contains only a hash of a requested transaction payload. ProtocolTransactionRequestGossipMsg = ProtocolMessage{TypeID: PROTOCOL_MSG_TYPE_TX_REQ_GOSSIP, MaxLength: GOSSIP_REQUESTED_TX_HASH_BYTES_LENGTH, SupportsDynamicLength: false} // The heartbeat packet containing the current latest solid and pruned milestone index. ProtocolHeartbeatMsg = ProtocolMessage{TypeID: PROTOCOL_MSG_TYPE_HEARTBEAT, MaxLength: GOSSIP_HEARTBEAT_MS_INDEX_BYTES_LENGTH * 2, SupportsDynamicLength: false} // The requested milestone index packet. ProtocolMilestoneRequestMsg = ProtocolMessage{TypeID: PROTOCOL_MSG_TYPE_MS_REQUEST, MaxLength: GOSSIP_REQUESTED_MS_INDEX_BYTES_LENGTH, SupportsDynamicLength: false} )
var DEFAULT_PROTOCOL = protocolDefinition{ // contains filtered or unexported fields }
var (
ErrInvalidSendParam = errors.New("invalid parameter passed to send")
)
var (
ErrVersionNotSupported = errors.New("Version not supported")
)
var Events = pluginEvents{ RemovedNeighbor: events.NewEvent(neighborCaller), NeighborPutIntoConnectedPool: events.NewEvent(neighborCaller), NeighborPutIntoInFlightPool: events.NewEvent(neighborCaller), NeighborPutBackIntoReconnectPool: events.NewEvent(neighborCaller), NeighborPutIntoReconnectPool: events.NewEvent(originAddrCaller), IncomingConnection: events.NewEvent(connectionCaller), NeighborHandshakeCompleted: events.NewEvent(handshakeCaller), SentTransaction: events.NewEvent(hornet.TransactionCaller), SentTransactionRequest: events.NewEvent(hornet.TransactionCaller), ReceivedTransaction: events.NewEvent(hornet.TransactionCaller), ProtocolError: events.NewEvent(hornet.TransactionCaller), Error: events.NewEvent(events.ErrorCaller), }
var PLUGIN = node.NewPlugin("Gossip", node.Enabled, configure, run)
var TCPServer = tcp.NewServer()
Functions ¶
func AddNeighbor ¶
func AddProtocolHeader ¶
func AddProtocolHeader(buf *bytes.Buffer, protoMsgType ProtocolMsgType, payloadLengthBytes uint16) error
Adds the protocol header to the given ByteBuffer.
func BroadcastTransaction ¶
func CreateHandshakePacket ¶
func CreateHandshakePacket(ownSourcePort uint16, ownByteEncodedCooAddress []byte, ownUsedMWM byte) ([]byte, error)
CreateHandshakePacket creates a new handshake packet.
ownSourcePort the node's own server socket port number return byte slice containing the handshake packet
func CreateHeartbeatPacket ¶
func CreateHeartbeatPacket(solidMilestoneIndex milestone_index.MilestoneIndex, prunedMilestoneIndex milestone_index.MilestoneIndex) ([]byte, error)
Creates a new heartbeat packet.
func CreateLegacyTransactionGossipPacket ¶
func CreateLegacyTransactionGossipPacket(truncatedTxData []byte, requestedHash []byte) ([]byte, error)
Creates a new transaction and request gossip packet.
The transaction to add into the packet requestedHash The hash of the requested transaction return a {@link ByteBuffer} containing the transaction gossip packet.
func CreateMilestoneRequestPacket ¶
func CreateMilestoneRequestPacket(requestedMilestoneIndex milestone_index.MilestoneIndex) ([]byte, error)
Creates a new milestone request packet.
requestedMilestoneIndex The index of the requested milestone return a {@link ByteBuffer} containing the milestone request packet.
func CreateTransactionGossipPacket ¶
Creates a new transaction gossip packet.
The transaction to add into the packet return a {@link ByteBuffer} containing the transaction gossip packet.
func CreateTransactionRequestGossipPacket ¶
Creates a transaction request gossip packet.
requestedHash The hash of the requested transaction return a {@link ByteBuffer} containing the transaction gossip packet.
func DebugPrintQueueStats ¶
func DebugPrintQueueStats()
func ExtractRequestedMilestoneIndex ¶
func ExtractRequestedMilestoneIndex(source []byte) (milestone_index.MilestoneIndex, error)
Copies the requested transaction hash from the given source data byte array into the given destination byte array.
source the transaction gossip packet data
func ExtractRequestedTxHash ¶
Copies the requested transaction hash from the given source data byte array into the given destination byte array.
source the transaction gossip packet data
func GetConnectedNeighbors ¶
func IsAddrBlacklisted ¶
func NewNeighborIdentity ¶
func ProcessReceivedLegacyTransactionGossipData ¶
func ProcessReceivedLegacyTransactionGossipData(protocol *protocol, data []byte)
func ProcessReceivedMilestoneRequest ¶
func ProcessReceivedMilestoneRequest(protocol *protocol, data []byte)
func ProcessReceivedTransactionGossipData ¶
func ProcessReceivedTransactionGossipData(protocol *protocol, txData []byte)
func ProcessReceivedTransactionRequestData ¶
func ProcessReceivedTransactionRequestData(protocol *protocol, reqHash []byte)
func RemoveNeighbor ¶
func Request ¶
func Request(hashes []trinary.Hash, reqMilestoneIndex milestone_index.MilestoneIndex)
Request adds a request to the queue
func RequestApprovees ¶
func RequestApprovees(tx *hornet.Transaction)
RequestApproveesAndRemove add the approvees of a tx to the queue and removes the tx from the queue
func RequestMilestone ¶
RequestMilestone requests trunk and branch of a milestone if they are missing ToDo: add it to the requestsWorkerPool
func RequestMulti ¶
func RequestMulti(hashes []trinary.Hash, reqMilestoneIndex milestone_index.MilestoneIndex)
RequestMulti adds multiple request to the queue at once
func SendHeartbeat ¶
func SendHeartbeat()
func SendMilestoneRequests ¶
func SendMilestoneRequests(solidMilestoneIndex milestone_index.MilestoneIndex, knownLatestMilestone milestone_index.MilestoneIndex)
Types ¶
type ConnectionFailureError ¶
type ConnectionFailureError struct {
Inner error
}
func NewConnectionFailureError ¶
func NewConnectionFailureError(cause error) *ConnectionFailureError
func (ConnectionFailureError) Cause ¶
func (e ConnectionFailureError) Cause() error
func (ConnectionFailureError) Error ¶
func (e ConnectionFailureError) Error() string
type ConnectionOrigin ¶
type ConnectionOrigin byte
const ( Inbound ConnectionOrigin = iota Outbound )
type Handshake ¶
type Handshake struct { // The state of the handshaking. State HeaderState ServerSocketPort uint16 SentTimestamp uint64 ByteEncodedCooAddress []byte MWM byte SupportedVersions []byte }
Defines information exchanged up on a new connection with a Neighbor.
func GetHandshakeFromByteSlice ¶
GetHandshakeFromByteSlice parses the given message into a Handshake object.
msg the buffer containing the handshake info return the Handshake object
func (Handshake) CheckNeighborSupportedVersion ¶
CheckNeighborSupportedVersion returns the highest supported protocol version by the neighbor
type HandshakeError ¶
type HandshakeError struct {
Inner error
}
func NewHandshakeError ¶
func NewHandshakeError(cause error) *HandshakeError
func (HandshakeError) Cause ¶
func (e HandshakeError) Cause() error
func (HandshakeError) Error ¶
func (e HandshakeError) Error() string
type HeaderState ¶
type HeaderState int32
const ( // The amount of bytes used for the coo address sent in a handshake packet. BYTE_ENCODED_COO_ADDRESS_BYTES_LENGTH = 49 HEADER_INIT HeaderState = 0 HEADER_FAILED HeaderState = 1 HEADER_OK HeaderState = 2 )
type Heartbeat ¶
type Heartbeat struct { SolidMilestoneIndex milestone_index.MilestoneIndex `json:"solid_milestone_index"` PrunedMilestoneIndex milestone_index.MilestoneIndex `json:"pruned_milestone_index"` }
func HeartbeatFromBytes ¶
type Neighbor ¶
type Neighbor struct { InitAddress *iputils.OriginAddress // The ip/port combination of the neighbor Identity string // The address IP address under which the neighbor is connected PrimaryAddress *iputils.IP // The IP addresses which were looked up during neighbor initialisation Addresses *iputils.NeighborIPAddresses // The protocol instance under which this neighbor operates Protocol *protocol // Events on this neighbor Events neighborEvents // Metrics about the neighbor Metrics *neighbor.NeighborMetrics // Whether the connection for this neighbor was handled inbound or was created outbound ConnectionOrigin ConnectionOrigin // Whether to place this neighbor back into the reconnect pool when the connection is closed MoveBackToReconnectPool bool // The neighbors latest heartbeat message LatestHeartbeat *Heartbeat }
func GetNeighbor ¶
func NewInboundNeighbor ¶
func NewOutboundNeighbor ¶
func NewOutboundNeighbor(originAddr *iputils.OriginAddress, primaryAddr *iputils.IP, port uint16, addresses *iputils.NeighborIPAddresses) *Neighbor
func (*Neighbor) IdentityOrAddress ¶
IdentityOrAddress gets the identity if set or the address otherwise.
func (*Neighbor) Reply ¶
func (neighbor *Neighbor) Reply(recHashBytes []byte, neighborReq *NeighborRequest)
Reply to the neighbor
func (*Neighbor) RequestLatestMilestone ¶
func (neighbor *Neighbor) RequestLatestMilestone()
Requests the latest milestone from the neigbor
func (*Neighbor) SendHeartbeat ¶
func (neighbor *Neighbor) SendHeartbeat()
Sends a heartbeat message to the given neighbor
func (*Neighbor) SendMilestoneRequest ¶
func (neighbor *Neighbor) SendMilestoneRequest(msIndex milestone_index.MilestoneIndex)
Sends a milestone request message to the given neighbor
func (*Neighbor) SendTransactionRequest ¶
func (neighbor *Neighbor) SendTransactionRequest()
Sends a transaction request to the given neighbor if we have something in our queue
func (*Neighbor) SetProtocol ¶
func (n *Neighbor) SetProtocol(protocol *protocol)
type NeighborConfig ¶
type NeighborInfo ¶
type NeighborInfo struct { Neighbor *Neighbor `json:"-"` Address string `json:"address"` Port uint16 `json:"port,omitempty"` Domain string `json:"domain,omitempty"` NumberOfAllTransactions uint32 `json:"numberOfAllTransactions"` NumberOfRandomTransactionRequests uint32 `json:"numberOfRandomTransactionRequests"` NumberOfNewTransactions uint32 `json:"numberOfNewTransactions"` NumberOfInvalidTransactions uint32 `json:"numberOfInvalidTransactions"` NumberOfStaleTransactions uint32 `json:"numberOfStaleTransactions"` NumberOfSentTransactions uint32 `json:"numberOfSentTransactions"` NumberOfDroppedSentPackets uint32 `json:"numberOfDroppedSentPackets"` ConnectionType string `json:"connectionType"` Connected bool `json:"connected"` }
func GetNeighbors ¶
func GetNeighbors() []NeighborInfo
type NeighborRequest ¶
type NeighborRequest struct {
// contains filtered or unexported fields
}
type PendingNeighborRequests ¶
type PendingNeighborRequests struct {
// contains filtered or unexported fields
}
func (*PendingNeighborRequests) AddLegacyTxRequest ¶
func (p *PendingNeighborRequests) AddLegacyTxRequest(neighbor *protocol, reqHashBytes []byte)
func (*PendingNeighborRequests) BlockFeedback ¶
func (p *PendingNeighborRequests) BlockFeedback(neighbor *protocol)
func (*PendingNeighborRequests) GetTxHash ¶
func (p *PendingNeighborRequests) GetTxHash() trinary.Hash
func (*PendingNeighborRequests) GetTxHashBytes ¶
func (p *PendingNeighborRequests) GetTxHashBytes() []byte
func (*PendingNeighborRequests) IsHashed ¶
func (p *PendingNeighborRequests) IsHashed() bool
func (*PendingNeighborRequests) IsHashing ¶
func (p *PendingNeighborRequests) IsHashing() bool
func (*PendingNeighborRequests) IsInvalid ¶
func (p *PendingNeighborRequests) IsInvalid() bool
type ProtocolHeader ¶
type ProtocolHeader struct { MsgType ProtocolMsgType ProtoMsg *ProtocolMessage MessageLength uint16 }
The ProtocolHeader denotes the protocol version used by the node and the TLV of the packet.
func ParseHeader ¶
func ParseHeader(buf []byte) (*ProtocolHeader, error)
Parses the given buffer into a ProtocolHeader. The IRI protocol uses a 4 bytes header denoting the version, type and length of a packet.
type ProtocolMessage ¶
type ProtocolMessage struct { TypeID ProtocolMsgType MaxLength uint16 SupportsDynamicLength bool }
func GetProtocolMsgFromTypeID ¶
func GetProtocolMsgFromTypeID(typeID ProtocolMsgType) (*ProtocolMessage, error)
Gets the ProtocolMessage corresponding to the given type id.
type ProtocolMsgType ¶
type ProtocolMsgType byte