models

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxArraySize int    = 10
	ModuleName   string = "Peer"
)

Functions

func ParseInterfaceMapMessageMetrics

func ParseInterfaceMapMessageMetrics(inputMap map[string]interface{}) (map[string]MessageMetric, error)

----- Deprecated Since the integration of PSQL as DB ----

ParseInterfaceMapMessageMetrics: Parse the inputMap into the MessageMetric format @param inputMap: a map of string interface @return a map of string MessageMetric

Types

type BeaconMetadataStamped

type BeaconMetadataStamped struct {
	Timestamp time.Time
	Metadata  common.MetaData
}

Basic BeaconMetadata struct that includes the timestamp of the received beacon metadata

func NewBeaconMetadata

func NewBeaconMetadata(bMetadata common.MetaData) BeaconMetadataStamped

UpdateBeaconMetadata: Update beacon Metadata of the peer. @param bMetadata: the Metadata object used to update the data

func (*BeaconMetadataStamped) IsEmpty

func (b *BeaconMetadataStamped) IsEmpty() bool

type BeaconStatusStamped

type BeaconStatusStamped struct {
	Timestamp time.Time
	Status    common.Status
}

Basic BeaconMetadata struct that includes The timestamp of the received beacon Status

func NewBeaconStatus

func NewBeaconStatus(bStatus common.Status) BeaconStatusStamped

UpdateBeaconStatus: Update beacon Status of the peer. @param bStatus: the Status object used to update the data

func ParseBeaconStatusFromBasicTypes

func ParseBeaconStatusFromBasicTypes(
	t time.Time,
	forkdigest string,
	finaRoot string,
	finaEpoch int64,
	headRoot string,
	headSlot int64) (BeaconStatusStamped, error)

func ParseBeaconStatusFromInterface

func ParseBeaconStatusFromInterface(input interface{}) (BeaconStatusStamped, error)

ParseBeaconStatusFromInterface: Parse the inputMap into the BeaconStatusStamped format @param inputMap: a map of string interface @return a map of string BeaconStatusStamped

func (*BeaconStatusStamped) IsEmpty

func (b *BeaconStatusStamped) IsEmpty() bool

type ClientDiversity

type ClientDiversity struct {
	Timestamp  time.Time `json:"snapshot_timestamp"`
	Prysm      int       `json:"prysm"`
	Lighthouse int       `json:"lighthouse"`
	Teku       int       `json:"teku"`
	Nimbus     int       `json:"nimbus"`
	Grandine   int       `json:"grandine"`
	Lodestar   int       `json:"lodestar"`
	Others     int       `json:"others"`
}

func NewClientDiversity

func NewClientDiversity() ClientDiversity

type MessageMetric

type MessageMetric struct {
	Count            uint64
	FirstMessageTime time.Time
	LastMessageTime  time.Time
}

Information regarding the messages received on a given topic

type Peer

type Peer struct {

	// PeerBASICS
	PeerId        string
	UserAgent     string
	ClientName    string
	ClientOS      string //TODO:
	ClientVersion string

	// PeerNetwork
	Ip              string
	Country         string
	CountryCode     string
	City            string
	Latency         float64
	MAddrs          []ma.Multiaddr
	Protocols       []string
	ProtocolVersion string

	// PeerMetrics
	ConnectedDirection    []string  // The directions of each connection event.
	IsConnected           bool      // If the peer is connected (CheckIfRealConnect).
	Attempted             bool      // If the peer has been attempted to stablish a connection.
	Succeed               bool      // If the connection attempt (outbound) has been successful.
	Attempts              uint64    // Number of attempts done.
	Error                 []string  // List of errors (also adding "None" errors), aligned with connection events.
	LastErrorTimestamp    time.Time // Timestamp of the last error reported for this peer.
	Deprecated            bool      // Flag to rummarize whether the peer is still valid for statistics or not. If true, the peer is not exported CSV / metrics.
	LastIdentifyTimestamp time.Time // Timestamp of the last time the peer was identified (get user agent...).

	NegativeConnAttempts []time.Time // List of dates when the peer retrieved a negative connection attempt (outbound) (if there is a possitive one, clean the array).
	ConnectionTimes      []time.Time // List of registered connections events.
	DisconnectionTimes   []time.Time // List of Disconnection Events.
	MetadataRequest      bool        // If the peer has been attempted to request its metadata.
	MetadataSucceed      bool        // If the peer has been successfully requested its metadata.

	LastExport int64 // Timestamp in seconds of the last exported time (backup for when we are loading the Peer).

	// Application layer / extra attributes
	Att map[string]interface{}

	// Message
	// Counters for the different topics
	MessageMetrics map[string]MessageMetric
}

Stores all the information related to a peer

func NewPeer

func NewPeer(peerId string) Peer

Default constructor

func (*Peer) AddMAddr

func (pm *Peer) AddMAddr(input_addr string) error

AddAddr: This method adds a new multiaddress in string format to the MAddrs array. @return Any error. Otherwise nil.

func (*Peer) AddNegConnAtt

func (pm *Peer) AddNegConnAtt(deprecated bool, err string)

AddNegConnAtt: This method will register a new negative connection attempt in the peer (outbound). @param deprecated: in case we want to activate the deprecation flag. @param err: error string to add to the peer error list.

func (*Peer) AddPositiveConnAttempt

func (pm *Peer) AddPositiveConnAttempt()

AddPositiveConnAttempt: This method will register a new positive connection attempt in the peer (outbound).

func (*Peer) CheckIfPeerRealConnect

func (pm *Peer) CheckIfPeerRealConnect() bool

CheckIfPeerRealConnect: This method will return whether the peer is currently connected or not. @return true if connected, false if not.

func (*Peer) ConnectionEvent

func (pm *Peer) ConnectionEvent(direction string, time time.Time)

ConnectionEvent: Register when a new connection was detected and the direction. @param direction: whether inbound or outbound. @param time: when the event happenned.

func (*Peer) DisconnectionEvent

func (pm *Peer) DisconnectionEvent(time time.Time)

DisconnectionEvent: Register when a new disconnection was detected. @param time: when the event happenned.

func (*Peer) ExtractPublicAddr

func (pm *Peer) ExtractPublicAddr() ma.Multiaddr

ExtractPublicMAddr: This method loops over all multiaddress and extract the first one that has a public IP. @return the found multiaddress, nil if error.

func (*Peer) FetchAttFromNewPeer

func (pm *Peer) FetchAttFromNewPeer(newPeer Peer)

FetchAttFromNewPeer: This method will read the custom attributes from the new peer and import them into our peer (pm). @param newPeer: the peer where to extract new information.

func (*Peer) FetchBasicHostInfoFromNewPeer

func (pm *Peer) FetchBasicHostInfoFromNewPeer(newPeer Peer)

FetchBasicHostInfoFromNewPeer: This method will read basic host info from the new peer and import it into our peer (pm). @param newPeer: the peer where to extract new information.

func (*Peer) FetchConnectionsFromNewPeer

func (pm *Peer) FetchConnectionsFromNewPeer(newPeer Peer)

FetchConnectionsFromNewPeer: This method will read connections from the new peer and import it into our peer (pm). @param newPeer: the peer where to extract new information.

func (*Peer) FetchPeerInfoFromNewPeer

func (pm *Peer) FetchPeerInfoFromNewPeer(newPeer Peer)

FetchPeerInfoFromPeer: This method will read information from a new peer, and update the self (pm) peer with the new peer's attributes. Keep in mind that only fields which are not empty in the new peer will be overwriten in the old peer. @param newPeer: the peer from where to get new information and update the old one.

func (Peer) FirstNegAttempt

func (pm Peer) FirstNegAttempt() (t time.Time, err error)

FirstNegAttempt: This method will calculate the last negative attempt time. @return the time of the first negative connection attempt with this peer and and error if applicable.

func (*Peer) GetAllMessagesCount

func (pm *Peer) GetAllMessagesCount() uint64

GetAllMessagesCount: Get total of messages received from that peer. @return a unit64 with the count.

func (*Peer) GetAtt

func (pm *Peer) GetAtt(key string) (interface{}, bool)

GetAtt reads custom attribute from the att map, returns interface and status of the read

func (*Peer) GetConnectedTime

func (pm *Peer) GetConnectedTime() float64

GetConnectedTime: This method will calculate the total connected time based on con/disc timestamps. This means the total time that the peer has been connected. Shifted some calculus to nanoseconds. Millisecons were leaving fields empty when exporting (less that 3 decimals). @return the resulting time in float64 format.

func (Peer) GetLastActivityTime

func (pm Peer) GetLastActivityTime() time.Time

GetLastActivityTime: Calculates the last activity recorded for the peer. @return last activity recorded for the peer.

func (*Peer) GetLastErrors

func (pm *Peer) GetLastErrors() []string

GetLastErrors: Returns the error in last position. The array also contains the same error if it was repeated consecutively. @return and array with the same error.

func (*Peer) GetNumOfMsgFromTopic

func (pm *Peer) GetNumOfMsgFromTopic(shortTopic string) uint64

GetNumOfMsgFromTopic: Get the number of messages that we got for a given topic. Note that the topic name is the shortened name i.e. BeaconBlock @param shortTopic: the topic to get count from. @return a uint64 with the total count.

func (Peer) IsDeprecated

func (pm Peer) IsDeprecated() bool

IsDeprecated: This method return the deprecated attirbute of the peer. @return true or false.

func (*Peer) IsEmpty

func (pm *Peer) IsEmpty() bool

IsEmpty: Check if the Peer struct is Empty or not @return boolean

func (Peer) LastNegAttempt

func (pm Peer) LastNegAttempt() (t time.Time, err error)

LastNegAttempt: This method will calculate the last negative attempt time. @return the time of the last negative connection attempt with this peer and and error if applicable.

func (*Peer) LogPeer

func (pm *Peer) LogPeer()

LogPeer: Log peer information

func (*Peer) MessageEvent

func (pm *Peer) MessageEvent(topicName string, time time.Time)

MessageEvent: Add one to the message count for the given topic. Also update the LastMessageTime. @param topicName: the topic to add a message on. @param time: when it was received.

func (*Peer) MetadataEvent

func (pm *Peer) MetadataEvent(success bool)

MetadataEvent: Add a Metadata Event to the given peer (successful or not). @param success: whether successful (to identify the peer) or not.

func (*Peer) ResetDynamicMetrics

func (pm *Peer) ResetDynamicMetrics()

ResetDynamicMetrics: It will reset the metrics by reinstancing the map.

func (*Peer) SetAtt

func (pm *Peer) SetAtt(key string, value interface{})

SetAtt adds a new custom attribute to the att map

func (*Peer) ToCsvLine

func (pm *Peer) ToCsvLine() string

ToCsvLine: This method will export all peer attributes into a single string in CSV format. @return the resulting string.

Jump to

Keyboard shortcuts

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