Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inital poke implementation #1037

Merged
merged 3 commits into from
Apr 6, 2022
Merged

Inital poke implementation #1037

merged 3 commits into from
Apr 6, 2022

Conversation

KonradStaniec
Copy link
Contributor

@KonradStaniec KonradStaniec commented Apr 5, 2022

Initial implementation of POKE mechanism i.e offering content to nodes which we discovered do not have it during content lookup.

One caveat for now:

  • Currently, due to how code is structured, we may only offer content which is in our db i.e it is in our range. It means we cannot offer content to nodes in case when content is in their range and not in our range. There is one one todo in offer procedure which would fix it i.e passing content directly of offer procedure, instead of using db as communication channel. It would also cause problem when we add deleting stuff from db, as offer-accept is asynchronous so the content could be deleted before be send it via uTP.

@KonradStaniec KonradStaniec requested a review from kdeme April 5, 2022 08:39
@KonradStaniec KonradStaniec marked this pull request as ready for review April 5, 2022 10:41
@@ -173,7 +183,17 @@ proc getBlock*(

# content is in range and valid, put into db
if h.portalProtocol.inRange(contentId):
h.contentDB.put(contentId, bodyContent)
# TODO this bit is quite troubling, currently we may trigger offer/accept
Copy link
Contributor

@kdeme kdeme Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning on putting the poke in the contentLookup proc just before it returns the content (with an asyncSpawn). I assume that you had the same in mind, but solved it like this for now because of the offer call using the database, hence the "quit troubling` wording?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I have also initially planning to add it in contentLookup, but having it here is the only way to make sure that:
a) Content is really in database, before triggering poke
b) Content is really validated before spreading it around

## offer directly to avoid potential problems when content is not really in database
## this will be especially important when we introduce deleting content
## from database
let keys = List[ByteList, contentKeysLimit].init(@[contentKey])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to do ContentKeysList.init() directly iirc

else:
# TODO: Should we do something with the node that failed responding our
# query?
discard

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace

# which means we cannot propagate content which is not in our range, but maybe
# in range of other nodes.
h.contentDB.put(contentId, headerContent.content)
# content is valid and in db we may propagate it through the network
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# content is valid and in db we may propagate it through the network
# content is valid and in the db, it may be propagated it through the network

@@ -144,12 +144,28 @@ type
Content

FoundContent* = object
dst*: Node
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dst*: Node
src*: Node

it is kind of the src node with respect to the found content

@@ -168,9 +184,16 @@ func localNode*(p: PortalProtocol): Node = p.baseProtocol.localNode
func neighbours*(p: PortalProtocol, id: NodeId, seenOnly = false): seq[Node] =
p.routingTable.neighbours(id = id, seenOnly = seenOnly)

proc inRangeImpl(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just be called inRange as it will be a directly useful proc also, and it shouldn't give naming symbol issues considering it has different parameter list.

nodes: seq[Node],
contentKey: ByteList,
contentId: ContentId) =
## Trigers asynchronous offer-accept interaction to provided nodes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Trigers asynchronous offer-accept interaction to provided nodes.
## Triggers asynchronous offer-accept interaction to provided nodes.

Comment on lines 866 to 868
# we only return nodes which may be interested in content
# also we do not need to chec for duplicates in nodesWithoutContent
# as we never make requests two times to the same node
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# we only return nodes which may be interested in content
# also we do not need to chec for duplicates in nodesWithoutContent
# as we never make requests two times to the same node
# Only return nodes which may be interested in content.
# No need to checc for duplicates in nodesWithoutContent
# as requests are never made two times to the same node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants