Commit Graph
118 Commits
Author SHA1 Message Date
PobreGato 28c65b6d59 don't overflow int when parsing SAM version 2026-09-26 01:24:43 -04:00
Elcoid 61e18baf68 sam: replace C-style 0/1 with C++-style false/true 2026-09-25 13:30:18 -04:00
Elcoid d1428cd2ae sam: fix inconsistencies in version negotiation of sam handshake
This commit fixes [issue #2570](https://github.com/PurpleI2P/i2pd/issues/2570).

The [specification of the SAM protocol](https://i2p.net/en/docs/api/samv3/)
says the following:
- "As of version 3.1 (I2P 0.9.14), the MIN and MAX parameters are optional."
- "SAM will always return the highest version possible given the MIN and MAX
  constraints"

Given this, the following handshakes do not change:
```
printf "HELLO VERSION MIN=3.1 MAX=3.3\n" | nc -q 0 127.0.0.1 7656
HELLO REPLY RESULT=OK VERSION=3.3

printf "HELLO VERSION MAX=3.3\n" | nc -q 0 127.0.0.1 7656
HELLO REPLY RESULT=OK VERSION=3.3

printf "HELLO VERSION MIN=31 MAX=31\n" | nc -q 0 127.0.0.1 7656
HELLO REPLY RESULT=OK VERSION=3.1
(periods are still optional)
```

But the following ones do (the responses before and after this commit
are included):
```
printf "HELLO VERSION MAX=3.4\n" | nc -q 0 127.0.0.1 7656
before: HELLO REPLY RESULT=NOVERSION
after:  HELLO REPLY RESULT=OK VERSION=3.3

printf "HELLO VERSION MIN=3.0\n" | nc -q 0 127.0.0.1 7656
before: HELLO REPLY RESULT=OK VERSION=3.0
after:  HELLO REPLY RESULT=OK VERSION=3.3

printf "HELLO VERSION MIN=3.1\n" | nc -q 0 127.0.0.1 7656
before: HELLO REPLY RESULT=OK VERSION=3.1
after:  HELLO REPLY RESULT=OK VERSION=3.3

printf "HELLO VERSION MIN=2.9\n" | nc -q 0 127.0.0.1 7656
before: HELLO REPLY RESULT=NOVERSION
after:  HELLO REPLY RESULT=OK VERSION=3.3

printf "HELLO VERSION\n" | nc -q 0 127.0.0.1 7656
before: HELLO REPLY RESULT=NOVERSION
after:  HELLO REPLY RESULT=OK VERSION=3.3

printf "HELLO VERSION MIN=3.3 MAX=3.1\n" | nc -q 0 127.0.0.1 7656
before: HELLO REPLY RESULT=OK VERSION=3.1
after:  HELLO REPLY RESULT=NOVERSION

printf "HELLO VERSION MIN=3.5 MAX=2.7\n" | nc -q 0 127.0.0.1 7656
before: HELLO REPLY RESULT=OK VERSION=2.7
after:  HELLO REPLY RESULT=NOVERSION

printf "HELLO VERSION MIN=2.7 MAX=3.5\n" | nc -q 0 127.0.0.1 7656
before: HELLO REPLY RESULT=NOVERSION
after:  HELLO REPLY RESULT=OK VERSION=3.3

printf "HELLO VERSION MIN=aab3vsg1df MAX=fd3gfbgf1bf\n" | nc -q 0 127.0.0.1 7656
before: HELLO REPLY RESULT=OK VERSION=3.1
after:  HELLO REPLY RESULT=NOVERSION
```

I included a script to automatically test these handshakes.
2026-09-25 10:52:05 -04:00
orignal 86cbb4b0de decline new session if previous one with same destination is being terminated 2026-09-17 14:30:37 -04:00
jpk68 1124b6259f http, i2pcontrol: use thread-safe snapshots for session/tunnel lists 2026-08-24 10:20:04 -04:00
jpk68 a57d375bf1 libi2pd: add missing checks and limits 2026-08-19 21:29:25 -04:00
jpk68 67404cd82f chore: fix memory safety issues 2026-08-18 15:43:44 -04:00
PobreGato f756d258b4 duplicated subsession id was never detected 2026-08-16 04:11:06 +03:00
PobreGato 3023c137c7 route datagrams to the subsession they belong to 2026-08-14 05:00:25 +03:00
PobreGato 218b26ebd9 datagram and raw subsessions for SAM 3.3 2026-08-14 04:14:16 +03:00
parsebulb d3266eb688 Don't close connection after PONG 2026-08-11 11:32:50 +02:00
Maxim Bunkov e16160b74d fix: cancel pending socket ops before close to prevent macOS crash
On macOS (kqueue), boost::asio throws an exception from pending
async_write/async_read handlers after the socket is closed.
This reaches io_service::run() as an uncaught exception and
terminates the process.

Call m_Socket.cancel() before shutdown/close in NTCP2, SAM,
I2PTunnel, and BOB so pending operations complete with
operation_aborted on a live socket.

Crash log (macOS 26, i2pd 2.61):
  libc++abi: terminating due to uncaught exception of type
  boost::wrapexcept<boost::system::system_error>:
  write_some: Bad file descriptor [system:9]

This is a kqueue-specific issue. On Linux (epoll), close() alone
cancels pending operations correctly. The fix is defensive on Linux
and required on macOS.
2026-08-04 02:04:30 +05:00
jpk68 d3ea3ca10c libi2pd_client: fix memory safety issues 2026-07-29 19:11:34 -04:00
acetone 345e85ea30 SAM: resolve datagram destinations like streams, supporting b32 and b33 hosts 2026-06-20 19:55:53 +03:00
acetone e58701d97c fixed SAM crash on shared destination teardown 2026-06-19 16:15:51 +03:00
Benson Muite 73623a4793 Replace deadline_timer by steady_timer
Prevent deprecation warnings when building.
2026-03-06 10:55:47 +03:00
orignal 3a42d2a150 Added FROM_PORT and TO_PORT datagram options 2026-02-01 09:36:26 -05:00
orignal 85466e80b5 support b32 addresses in datagrams 2026-01-30 15:12:26 -05:00
orignal a1b0f2a505 return base64 of ident instead full address for datagram3 2026-01-30 12:10:16 -05:00
orignal d52ad52874 fixed incorrect params length calculation if follow on data 2025-12-15 17:27:10 -05:00
orignal 12895b5744 use Mapping for local destination params 2025-10-13 17:33:53 -04:00
orignal dc9cdf941d pass options from Datagram2 and Datagram3 to handlers 2025-09-25 20:47:08 -04:00
orignal 3522a3180b implement PING command 2025-08-31 17:50:02 -04:00
orignal 83f9e1098d decline master session if SAM version is less than 3.3 2025-08-14 15:58:42 -04:00
orignal 7dd174d32c extract and check VERSION 2025-08-14 15:44:48 -04:00
orignal d496b15249 handle SESSION ADD without FROM_PORT 2025-08-13 17:16:56 -04:00
orignal aeca4c3fc7 fixed #2215. Check streaming destination during cleanup 2025-08-03 16:34:31 -04:00
orignal b6f5308242 used enum class for SAMSocketType and SAMSessionType 2025-08-02 11:31:26 -04:00
orignal d5769080c8 handle session with STYLE=DATAGRAM2 and STYLE=DATAGRAM3 2025-07-23 12:54:46 -04:00
orignal 49569d36e5 calculate message size properly 2025-07-21 12:51:40 -04:00
orignal 99e4bda685 pass actual string size to Process* methods 2025-07-08 13:18:54 -04:00
orignal 181edce55a pass buffer as std::string_stream 2025-07-06 18:47:52 -04:00
orignal 1862f28a98 extract params from std::string_view 2025-07-06 16:45:47 -04:00
orignal 88375bf9c0 fixed build for older gcc 2025-07-05 21:41:35 -04:00
orignal 59d1695ee5 use std::string_view to extract params 2025-07-05 21:06:49 -04:00
nobs2p d440b5bf09 Fix FORWARD session host handling in SAM; refactor SAMSocket::ProcessStreamForward
- Fixed validation of HOST and PORT parameters for FORWARD sessions:
  - Improved IP address parsing with fallback to 127.0.0.1 if invalid
- Added checks for required parameters (ID, HOST, PORT)
- General cleanup and refactoring for improved readability and stability

Signed-off-by: nobs2p <nobs2p@i2pmail.org>
2025-05-20 00:07:56 +03:00
orignal aece5bb16c don't exceed stream max send buffer size 2025-05-03 08:47:49 -04:00
orignal 539cd5a656 max i2p stream buffer size 2025-05-02 13:36:59 -04:00
orignal 9d44a32e4c fixed #2183. Give more time to close streams after session disconnect if needed 2025-04-24 16:37:50 -04:00
orignal 8e6b9370d0 use ToBase64 for incoming stream accept 2025-03-17 19:00:48 -04:00
orignal c2f6731296 don't use fixed size buffer for local destination's keys 2025-03-16 18:06:12 -04:00
orignal d93a80cd2b Support v1 datagram sessions without port 2025-03-16 11:07:17 -04:00
orignal 4fa5cec0dc fixed termination deadlock if SAM session is active 2025-01-23 14:12:52 -05:00
orignal ffd18baf30 support boost 1.87 2024-11-25 16:00:06 -05:00
weko 5b93558bd0 Add support for multiple udp server tunnels on one destionation 2024-01-25 01:05:58 +00:00
orignal cd087568b5 reply with CANT_REACH_PEER if connect to outselves 2024-01-09 21:02:11 -05:00
orignal 8bc58daa5a fixed #2004. Check supported crypto 2024-01-07 18:42:34 -05:00
orignal d327533b56 close unclaimed acceptors after 3 seconds 2023-11-17 18:50:52 -05:00
orignal 94255ebaf4 STREAM ACCEPT queue 2023-11-17 13:44:30 -05:00
orignal 1e6edf06a2 send already accepting error response 2023-09-28 16:05:13 -04:00