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

feat p2p_daemon: add API to call peer handle #181

Merged
merged 9 commits into from Mar 21, 2021

Conversation

skobellev
Copy link
Collaborator

Relates: #177


def _initialize(self, proc_args: tp.List[str]) -> None:
self._host_port = find_open_port()
self._daemon_listen_port = find_open_port()
Copy link
Member

Choose a reason for hiding this comment

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

Note: these ports can randomly become equal.

I do not insist, but i'd recommend:

  • supporting an option to specify host/listen port manually
  • switching to a with find_open_port(...) version that guarantees that the port is unique

Both of these can be done here or in a subsequent PR, whichever you prefer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed both

@justheuristic
Copy link
Member

justheuristic commented Mar 20, 2021

[note: we can merge this despite RTFD build failure because this failure will be automatically resolved in #183 . The target branch for this merge is libp2p, not master.]

Copy link
Member

@borzunov borzunov left a comment

Choose a reason for hiding this comment

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

I've found some issues but enjoyed reading this PR in general. Thank you for the nice code style :)

I am okay if you fix the non-critical issues marked with nit: in later PRs (but before the code comes to master).

hivemind/p2p/p2p_daemon.py Outdated Show resolved Hide resolved
hivemind/p2p/p2p_daemon.py Outdated Show resolved Hide resolved
hivemind/p2p/p2p_daemon.py Show resolved Hide resolved
hivemind/p2p/p2p_daemon.py Outdated Show resolved Hide resolved
hivemind/p2p/p2p_daemon.py Outdated Show resolved Hide resolved
hivemind/p2p/p2p_daemon.py Outdated Show resolved Hide resolved
chunks.append(data)
curr_length += len(data)

return pickle.loads(b''.join(chunks))
Copy link
Member

Choose a reason for hiding this comment

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

If the stream data may come from another computer (now or in future), unpickling it may lead to remote code execution, a serious security risk (see #155). To overcome this, you can use MSGPackSerializer and implement sending exceptions as a special case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suggest that we discuss possible security risk at the meeting, and fix this issue later if necessary

Copy link
Member

Choose a reason for hiding this comment

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

Okay :)

configargparse>=1.2.3
trio==0.16.0
Copy link
Member

Choose a reason for hiding this comment

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

nit: Replace == to >= to allow updating trio and modules depending on it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You have to install exactly this version to make p2pclient work with python 3.8. Otherwise import errors arise.

tests/test_p2p_daemon.py Outdated Show resolved Hide resolved
hivemind/p2p/p2p_daemon.py Outdated Show resolved Hide resolved

while curr_length < content_length:
async def _receive_exactly(self, stream, n_bytes, max_bytes=1 << 16):
while len(self._buffer) < n_bytes:
data = await stream.receive_some(max_bytes)
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to replace self._buffer with a local variable buffer, remove max_bytes, and just write:

data = await stream.receive_some(n_bytes - len(buffer))

Then you'll never get more data than needed, so you won't need to save the remainder in self._buffer.

Copy link
Member

@borzunov borzunov Mar 21, 2021

Choose a reason for hiding this comment

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

@skobellev Please note this comment as well :)

(I've approved the PR in advance while assuming that you'll fix it :) )

@skobellev skobellev merged commit 2abf3c1 into learning-at-home:libp2p Mar 21, 2021
justheuristic pushed a commit that referenced this pull request Apr 13, 2021
* Extend P2P api

* Add tests for new api

* Add p2pclient dependencies

* Test P2P from different processes

* Fix typo in tests

* Add default initialization

* Fix daemon ports assignment

* Replace del with __del__ in tests

* Read from input stream with receive_exactly

Co-authored-by: Ilya Kobelev <ilya.kobellev@gmail.com>
MaximKsh pushed a commit that referenced this pull request Apr 20, 2021
* Extend P2P api

* Add tests for new api

* Add p2pclient dependencies

* Test P2P from different processes

* Fix typo in tests

* Add default initialization

* Fix daemon ports assignment

* Replace del with __del__ in tests

* Read from input stream with receive_exactly

Co-authored-by: Ilya Kobelev <ilya.kobellev@gmail.com>
MaximKsh pushed a commit that referenced this pull request May 14, 2021
* Extend P2P api

* Add tests for new api

* Add p2pclient dependencies

* Test P2P from different processes

* Fix typo in tests

* Add default initialization

* Fix daemon ports assignment

* Replace del with __del__ in tests

* Read from input stream with receive_exactly

Co-authored-by: Ilya Kobelev <ilya.kobellev@gmail.com>
MaximKsh pushed a commit that referenced this pull request May 14, 2021
* Extend P2P api

* Add tests for new api

* Add p2pclient dependencies

* Test P2P from different processes

* Fix typo in tests

* Add default initialization

* Fix daemon ports assignment

* Replace del with __del__ in tests

* Read from input stream with receive_exactly

Co-authored-by: Ilya Kobelev <ilya.kobellev@gmail.com>
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.

None yet

3 participants