introduce ProtocolBehavior property

Start implementing non-honest strategies.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-09-04 14:08:57 +02:00
parent 5ae5295f26
commit 5af9a06258
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
1 changed files with 10 additions and 0 deletions

View File

@ -159,7 +159,12 @@ type
tableIpLimits*: TableIpLimits
bitsPerHop*: int
ProtocolBehavior* = enum
honest, # normal protocol behavior
noresponse # does not respond to messages (can still send out messages)
Protocol* = ref object
behavior*: ProtocolBehavior
localNode*: Node
privateKey: PrivateKey
transport*: Transport[Protocol] # exported for tests
@ -450,6 +455,9 @@ proc handleFindValue(d: Protocol, fromId: NodeId, fromAddr: Address,
proc handleMessage(d: Protocol, srcId: NodeId, fromAddr: Address,
message: Message) =
if d.behavior == ProtocolBehavior.noresponse:
trace "Behavior=noresponse -> ignoring message", n = d.localNode, src = srcId
return
case message.kind
of ping:
discovery_message_requests_incoming.inc()
@ -1353,6 +1361,7 @@ proc newProtocol*(
rng)
result = Protocol(
behavior: ProtocolBehavior.honest,
privateKey: privKey,
localNode: node,
bootstrapRecords: @bootstrapRecords,
@ -1390,6 +1399,7 @@ proc newProtocol*(
doAssert rng != nil, "RNG initialization failed"
result = Protocol(
behavior: ProtocolBehavior.honest,
privateKey: privKey,
localNode: node,
bootstrapRecords: @bootstrapRecords,