Commit Graph

1880 Commits

Author SHA1 Message Date
523cc1810a fix(examples/echo/echo.py): Add max message length to stream.read
Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
2025-06-10 03:34:52 +05:30
286752c517 Merge pull request #658 from AkMo3/main
fix: add connection state for net stream and gracefully handle failure
2025-06-10 01:03:18 +05:30
390ac2eb26 Merge branch 'main' into main 2025-06-10 00:53:59 +05:30
13d730ae5c fix: improve types according to new typecheck 2025-06-09 19:10:15 +00:00
4e9fa87477 Updated examples to automatically use random port (#661)
* updated examples to automatically use random port

* Refactor examples to use shared utils for port selection (#1)

---------

Co-authored-by: acul71 <34693171+acul71@users.noreply.github.com>
2025-06-09 12:59:11 -06:00
47ae20d29c fix: run pytests parallely in CI and makefile 2025-06-09 18:58:51 +00:00
f7757fa726 docs: add documentation and examples for new NetStream state management 2025-06-09 18:58:17 +00:00
5bc4d01eea fix: add connection states for net stream
Other changes:
1. Add operation validation based on states
2. Gracefully handle exceptions and cleanup
2025-06-09 18:58:17 +00:00
c83fc1582d build(deps): bump fastecdsa from 1.7.5 to 2.3.2 (#669)
Bumps [fastecdsa](https://github.com/AntonKueltz/fastecdsa) from 1.7.5 to 2.3.2.
- [Release notes](https://github.com/AntonKueltz/fastecdsa/releases)
- [Changelog](https://github.com/AntonKueltz/fastecdsa/blob/main/CHANGELOG.md)
- [Commits](https://github.com/AntonKueltz/fastecdsa/compare/v1.7.5...v2.3.2)

---
updated-dependencies:
- dependency-name: fastecdsa
  dependency-version: 2.3.2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-09 12:44:45 -06:00
22d93b39ae Add ttl for peer data expiration (#655)
* Add ttl and last_identified to peerdata

* Add test for ttl

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* Fix lint and add newsfragments

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* Fix failing ci

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* fix ttl time from 600 to 120

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* fix test ttl timeout and lint errors

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* Fix docstrings

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* rebase main

* remove print statement

---------

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>
Co-authored-by: pacrob <5199899+pacrob@users.noreply.github.com>
2025-06-09 12:42:59 -06:00
bdadec7519 ft. modernise py-libp2p (#618)
* fix pyproject.toml , add ruff

* rm lock

* make progress

* add poetry lock ignore

* fix type issues

* fix tcp type errors

* fix text example - type error - wrong args

* add setuptools to dev

* test ci

* fix docs build

* fix type issues for new_swarm & new_host

* fix types in gossipsub

* fix type issues in noise

* wip: factories

* revert factories

* fix more type issues

* more type fixes

* fix: add null checks for noise protocol initialization and key handling

* corrected argument-errors in peerId and Multiaddr in peer tests

* fix: Noice - remove redundant type casts in BaseNoiseMsgReadWriter

* fix: update test_notify.py to use SwarmFactory.create_batch_and_listen, fix type hints, and comment out ClosedStream assertions

* Fix type checks for pubsub module

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* Fix type checks for pubsub module-tests

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* noise: add checks for uninitialized protocol and key states in PatternXX

Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>

* pubsub: add None checks for optional fields in FloodSub and Pubsub

Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>

* Fix type hints and improve testing

Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>

* remove redundant checks

Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>

* fix build issues

* add optional to trio service

* fix types

* fix type errors

* Fix type errors

Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>

* fixed more-type checks in crypto and peer_data files

* wip: factories

* replaced union with optional

* fix: type-error in interp-utils and peerinfo

* replace pyright with pyrefly

* add pyrefly.toml

* wip: fix multiselect issues

* try typecheck

* base check

* mcache test fixes , typecheck ci update

* fix ci

* will this work

* minor fix

* use poetry

* fix wokflow

* use cache,fix err

* fix pyrefly.toml

* fix pyrefly.toml

* fix cache in ci

* deploy commit

* add main baseline

* update to v5

* improve typecheck ci (#14)

* fix typo

* remove holepunching code (#16)

* fix gossipsub typeerrors (#17)

* fix: ensure initiator user includes remote peer id in handshake (#15)

* fix ci (#19)

* typefix: custom_types | core/peerinfo/test_peer_info | io/abc | pubsub/floodsub | protocol_muxer/multiselect (#18)

* fix: Typefixes in PeerInfo  (#21)

* fix minor type issue (#22)

* fix type errors in pubsub (#24)

* fix: Minor typefixes in tests (#23)

* Fix failing tests for type-fixed test/pubsub (#8)

* move pyrefly & ruff to pyproject.toml & rm .project-template (#28)

* move the async_context file to tests/core

* move crypto test to crypto folder

* fix: some typefixes (#25)

* fix type errors

* fix type issues

* fix: update gRPC API usage in autonat_pb2_grpc.py (#31)

* md: typecheck ci

* rm comments

* clean up : from review suggestions

* use | None over Optional as per new python standards

* drop supporto for py3.9

* newsfragments

---------

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>
Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
Co-authored-by: acul71 <luca.pisani@birdo.net>
Co-authored-by: kaneki003 <sakshamchauhan707@gmail.com>
Co-authored-by: sukhman <sukhmansinghsaluja@gmail.com>
Co-authored-by: varun-r-mallya <varunrmallya@gmail.com>
Co-authored-by: varunrmallya <100590632+varun-r-mallya@users.noreply.github.com>
Co-authored-by: lla-dane <abhinavagarwalla6@gmail.com>
Co-authored-by: Collins <ArtemisfowlX@protonmail.com>
Co-authored-by: Abhinav Agarwalla <120122716+lla-dane@users.noreply.github.com>
Co-authored-by: guha-rahul <52607971+guha-rahul@users.noreply.github.com>
Co-authored-by: Sukhman Singh <63765293+sukhman-sukh@users.noreply.github.com>
Co-authored-by: acul71 <34693171+acul71@users.noreply.github.com>
Co-authored-by: pacrob <5199899+pacrob@users.noreply.github.com>
2025-06-09 11:39:59 -06:00
d020bbc066 Add time_since_last_publish (#642)
Added `time_since_last_publish` field to gossipsub. Took reference from
https://github.com/libp2p/go-libp2p-pubsub/blob/master/gossipsub.go#L1224

Issue https://github.com/libp2p/py-libp2p/issues/636

## How was it fixed?
whenever someone publishes message to a topic or set of topics,
`time_since_last_publish` gets updated and whenever we clear fanout
peers or time exceeds ttl, we clear `time_since_last_publish` from dict.

### To-Do

Creating draft PR for now. Tests and type-binding is left for this
issue.
#### Cute Animal Picture

![put a cute animal picture link inside the
parentheses](https://i.etsystatic.com/27171676/r/il/eedb08/5303109239/il_570xN.5303109239_4o61.jpg)
2025-06-09 00:53:36 +05:30
00f10dbec3 Merge branch 'main' into add-last-publish 2025-06-08 19:19:30 +05:30
d75886b180 renamed newsfragment file causing docs ci failure 2025-06-06 17:55:40 +05:30
5ca6f26933 feat: Add blacklisting of peers (#651)
* init

* remove blacklist validation after hello packet

* add docs and newsfragment
2025-06-05 09:10:04 -06:00
a3c9ac61e6 Improve performance of read from daemon test (#646)
Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
2025-06-05 07:25:59 -06:00
d4785b9e26 Add newsfragments to the PR
Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>
2025-06-05 14:00:23 +05:30
cef217358f fixed fanout_heartbeat bug and gossipsub join test 2025-06-05 13:39:07 +05:30
338672214c Add test for time_since_last_publish
Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>
2025-06-04 14:15:07 +05:30
c2046e6aa4 Add time_since_last_publish 2025-06-01 01:47:47 +05:30
67ab6e27d8 feat: implement AsyncContextManager for IMuxedStream to support async… (#629)
* feat: implement AsyncContextManager for IMuxedStream to support async with

* doc: add newsfragment
2025-05-30 08:44:33 -06:00
67ca1d7769 todo: handled ls command in multiselect.py (#622) 2025-05-27 20:18:37 -06:00
5496b2709a Resolved type-checking error in PubSub example test. (#627) 2025-05-25 19:14:58 -06:00
481be5d63d todo: parse listen_addrs to set transport in SwarmBuilder (#616) 2025-05-25 18:57:30 -06:00
386f0a2299 Bump version: 0.2.6 → 0.2.7 2025-05-22 15:27:03 -06:00
76f17cf133 Compile release notes for v0.2.7 2025-05-22 15:26:20 -06:00
276b9b7339 Implemented multi-error handling in MultiError() class (#614)
* Implemented multi-error handling in MultiError() class

* Added newsfragement file and test

* updated doc-string and list-struct

* updating docstring
2025-05-22 15:22:38 -06:00
4b1860766d Feat: Adding Yamux as default multiplexer, keeping Mplex as fallback (#538)
* feat: Replace mplex with yamux as default multiplexer in py-libp2p

* Retain Mplex alongside Yamux in new_swarm with messaging that Yamux is preferred

* moved !BBHII to a constant YAMUX_HEADER_FORMAT at the top of yamux.py with a comment explaining its structure

* renamed the news fragment to 534.feature.rst and updated the description

* renamed the news fragment to 534.feature.rst and updated the description

* added a docstring to clarify that Yamux does not support deadlines natively

* Remove the __main__ block entirely from test_yamux.py

* Replaced the print statements in test_yamux.py with logging.debug

* Added a comment linking to the spec for clarity

* Raise NotImplementedError in YamuxStream.set_deadline per review

* Add muxed_conn to YamuxStream and test deadline NotImplementedError

* Fix Yamux implementation to meet libp2p spec

* Fix None handling in YamuxStream.read and Yamux.read_stream

* Fix test_connected_peers.py to correctly handle peer connections

* fix: Ensure StreamReset is raised on read after local reset in yamux

* fix: Map MuxedStreamError to StreamClosed in NetStream.write for Yamux

* fix: Raise MuxedStreamReset in Yamux.read_stream for closed streams

* fix: Correct Yamux stream read behavior for NetStream tests

Fixed 	est_net_stream_read_after_remote_closed by updating NetStream.read to raise StreamEOF when the stream is remotely closed and no data is available, aligning with test expectations and Fixed 	est_net_stream_read_until_eof by modifying YamuxStream.read to block until the stream is closed (
ecv_closed=True) for
=-1 reads, ensuring data is only returned after remote closure.

* fix: Correct Yamux stream read behavior for NetStream tests

Fixed 	est_net_stream_read_after_remote_closed by updating NetStream.read to raise StreamEOF when the stream is remotely closed and no data is available, aligning with test expectations and Fixed 	est_net_stream_read_until_eof by modifying YamuxStream.read to block until the stream is closed (
ecv_closed=True) for
=-1 reads, ensuring data is only returned after remote closure.

* fix: raise StreamEOF when reading from closed stream with empty buffer

* fix: prioritize returning buffered data even after stream reset

* fix: prioritize returning buffered data even after stream reset

* fix: Ensure test_net_stream_read_after_remote_closed_and_reset passes in full suite

* fix: Add __init__.py to yamux module to fix documentation build

* fix: Add __init__.py to yamux module to fix documentation build

* fix: Add libp2p.stream_muxer.yamux to libp2p.stream_muxer.rst toctree

* fix: Correct title underline length in libp2p.stream_muxer.yamux.rst

* fix: Add a = so that is matches the libp2p.stream\_muxer.yamux length

* fix(tests): Resolve race condition in network notification test

* fix: fixing failing tests and examples with yamux and noise

* refactor: remove debug logging and improve x25519 tests

* fix: Add functionality for users to choose between Yamux and Mplex

* fix: increased trio sleep to 0.1 sec for slow environment

* feat: Add test for switching between Yamux and mplex

* refactor: move host fixtures to interop tests

* chore: Update __init__.py removing unused import

removed unused
```python
import os
import logging
```

* lint: fix import order

* fix: Resolve conftest.py conflict by removing trio test support

* fix: Resolve test skipping by keeping trio test support

* Fix: add a newline at end of the file

---------

Co-authored-by: acul71 <luca.pisani@birdo.net>
Co-authored-by: acul71 <34693171+acul71@users.noreply.github.com>
2025-05-22 14:01:51 -06:00
18c6f529c6 Feat/issue 605 debug logging via env variable (#608)
* feat: Debug Logging via Environment Variable

* refactor: deleted libp2p/utils.py

* fix: double messages logging fix

* doc: add logging info to getting_started.rst
2025-05-20 14:07:22 -06:00
4a53fc3111 Direct Peers : Gossipsub V1.1 (#594)
* added basic structure for direct peers

* added direct connect heartbeat

* added logic to reject GRAFT from direct peers

* added invocation of direct_connect_heartbeat

* updated _get_peers_to_send to include direct peers

* fixed failing gossipsub core and demo tests

* fixed failing test_examples.py

* add tests for peer management

* fix lint

* update tests

* fixed direct_peers type and peer_records test

* fixed failing gossipsub direct peers test

* added reject graft test

* updated reconnection test

* added newsfragment

* improved reject graft test

* updated default value for direct peers

* renamed direct_connect_init_delay parameter

* reverted back to direct_connect_initial_delay param name

---------

Co-authored-by: Khwahish Patel <khwahish.p1@ahduni.edu.in>
2025-05-20 07:31:57 -06:00
5b40e2551d doc: fix discord server link (#609)
* fix-discord-server-link
2025-05-16 10:38:49 -06:00
d34d6df1c5 Update 586.bugfix.rst
Remove extra `
2025-05-15 13:49:02 -06:00
eba4805a76 Add news fragment 2025-05-15 13:49:02 -06:00
e56974078a Fix exception handling 2025-05-15 13:49:02 -06:00
745458cdff Reduce logging level to debug in TCPListener.listen() 2025-05-15 13:49:02 -06:00
bb21af7694 Adds exception handling in TCPListener.listen() 2025-05-15 13:49:02 -06:00
e076a038bc Bump version: 0.2.5 → 0.2.6 2025-05-12 13:46:14 -06:00
ede850d943 Compile release notes for v0.2.6 2025-05-12 13:45:35 -06:00
9798db3932 fix towncrier config and correct links in release_notes 2025-05-12 13:22:12 -06:00
0430ad397f doc: fix broken newsfragment link in contributing 2025-05-11 16:57:14 -06:00
dc2f77ccbd Fix check-rst-files hook to work cross-platform 2025-05-09 19:21:42 -06:00
6064c96563 feat(autonat): add make targets for autonat protobuf generation and formatting 2025-05-09 17:31:15 -06:00
05d89cb20e added all and docs dependencies in tox.ini for testenv:docs 2025-05-09 17:31:15 -06:00
171b2a26e3 removed grpcio dependency from setup.py 2025-05-09 17:31:15 -06:00
e9674d2bca refractored Peer_Info to PeerInfo as imports 2025-05-09 17:31:15 -06:00
99238403dd added logger in test file and added dependency in tox.ini 2025-05-09 17:31:15 -06:00
04da30b7fe refractor: remove suppress warning in conf.py 2025-05-09 17:31:15 -06:00
8d98e93c27 refractor: remove suppress warning in conf.py 2025-05-09 17:31:15 -06:00
d55c57769f Refactor: changed PeerInfo to Peer_Info in autonat.proto to avoid conflicts 2025-05-09 17:31:15 -06:00
627c2cfe8e removed unused imports from conf.py 2025-05-09 17:31:15 -06:00