github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/alsp.go (about) 1 package network 2 3 import ( 4 "github.com/onflow/flow-go/model/flow" 5 "github.com/onflow/flow-go/module/component" 6 "github.com/onflow/flow-go/network/channels" 7 ) 8 9 // Misbehavior is the type of malicious action concerning a message dissemination that can be reported by the engines. 10 // The misbehavior is used to penalize the misbehaving node at the protocol level concerning the messages that the current 11 // node has received from the misbehaving node. 12 type Misbehavior string 13 14 func (m Misbehavior) String() string { 15 return string(m) 16 } 17 18 // MisbehaviorReporter is an interface that is used to report misbehavior of a remote node. 19 // The misbehavior is reported to the networking layer to penalize the misbehaving node. 20 type MisbehaviorReporter interface { 21 // ReportMisbehavior reports the misbehavior of a node on sending a message to the current node that appears valid 22 // based on the networking layer but is considered invalid by the current node based on the Flow protocol. 23 // The misbehavior is reported to the networking layer to penalize the misbehaving node. 24 // Implementation must be thread-safe and non-blocking. 25 ReportMisbehavior(MisbehaviorReport) 26 } 27 28 // MisbehaviorReport abstracts the semantics of a misbehavior report. 29 // The misbehavior report is generated by the engine that detects a misbehavior on a delivered message to it. The 30 // engine crafts a misbehavior report and sends it to the networking layer to penalize the misbehaving node. 31 type MisbehaviorReport interface { 32 // OriginId returns the ID of the misbehaving node. 33 OriginId() flow.Identifier 34 35 // Reason returns the reason of the misbehavior. 36 Reason() Misbehavior 37 38 // Penalty returns the penalty value of the misbehavior. 39 Penalty() float64 40 } 41 42 // MisbehaviorReportManager abstracts the semantics of handling misbehavior reports. 43 // The misbehavior report manager is responsible for handling misbehavior reports that are sent by the engines. 44 // The misbehavior report manager is responsible for penalizing the misbehaving node and disallow-listing the node 45 // if the overall penalty of the misbehaving node drops below the disallow-listing threshold. 46 type MisbehaviorReportManager interface { 47 component.Component 48 // HandleMisbehaviorReport handles the misbehavior report that is sent by the engine. 49 // The implementation of this function should penalize the misbehaving node and report the node to be 50 // disallow-listed if the overall penalty of the misbehaving node drops below the disallow-listing threshold. 51 // The implementation of this function should be thread-safe and non-blocking. 52 HandleMisbehaviorReport(channels.Channel, MisbehaviorReport) 53 }