mirror of
https://github.com/go-i2p/go-i2cp.git
synced 2025-12-20 15:15:53 -05:00
Refactor I2CP constants and update protocol usage in tests
This commit is contained in:
19
constants.go
19
constants.go
@@ -1,5 +1,16 @@
|
|||||||
package go_i2cp
|
package go_i2cp
|
||||||
|
|
||||||
|
// I2CP Protocol Constants
|
||||||
|
//
|
||||||
|
// This file contains constants defined by the I2CP specification for the
|
||||||
|
// I2P Control Protocol. I2CP is a lower-level protocol for managing sessions,
|
||||||
|
// leases, and message routing between I2P clients and routers.
|
||||||
|
//
|
||||||
|
// Note: This library focuses solely on I2CP. Higher-level application protocols
|
||||||
|
// such as streaming (protocol 6) and datagram (protocol 17/18) are intentionally
|
||||||
|
// NOT defined here as they are built on top of I2CP, not part of the I2CP spec.
|
||||||
|
// Applications using I2CP can define their own protocol identifiers as needed.
|
||||||
|
|
||||||
// I2CP Client Constants
|
// I2CP Client Constants
|
||||||
// Moved from: client.go
|
// Moved from: client.go
|
||||||
const (
|
const (
|
||||||
@@ -84,14 +95,6 @@ const (
|
|||||||
// Moved from: client.go
|
// Moved from: client.go
|
||||||
const ROUTER_CAN_HOST_LOOKUP uint32 = 1
|
const ROUTER_CAN_HOST_LOOKUP uint32 = 1
|
||||||
|
|
||||||
// Protocol Constants
|
|
||||||
// Moved from: client.go
|
|
||||||
const (
|
|
||||||
PROTOCOL_STREAMING = 6
|
|
||||||
PROTOCOL_DATAGRAM = 17
|
|
||||||
PROTOCOL_RAW_DATAGRAM = 18
|
|
||||||
)
|
|
||||||
|
|
||||||
// Host Lookup Type Constants
|
// Host Lookup Type Constants
|
||||||
// Moved from: client.go
|
// Moved from: client.go
|
||||||
const (
|
const (
|
||||||
|
|||||||
11
go.mod
11
go.mod
@@ -1,13 +1,16 @@
|
|||||||
module github.com/go-i2p/go-i2cp
|
module github.com/go-i2p/go-i2cp
|
||||||
|
|
||||||
go 1.24.2
|
go 1.24.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-i2p/logger v0.0.0-20241123010126-3050657e5d0c
|
github.com/go-i2p/logger v0.0.1
|
||||||
golang.org/x/crypto v0.39.0
|
golang.org/x/crypto v0.45.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
golang.org/x/sys v0.33.0 // indirect
|
github.com/stretchr/testify v1.10.0 // indirect
|
||||||
|
golang.org/x/sys v0.38.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
24
go.sum
24
go.sum
@@ -1,20 +1,24 @@
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/go-i2p/logger v0.0.0-20241123010126-3050657e5d0c h1:VTiECn3dFEmUlZjto+wOwJ7SSJTHPLyNprQMR5HzIMI=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||||
github.com/go-i2p/logger v0.0.0-20241123010126-3050657e5d0c/go.mod h1:te7Zj3g3oMeIl8uBXAgO62UKmZ6m6kHRNg1Mm+X8Hzk=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/go-i2p/logger v0.0.1 h1:OFDZMjqiNXbPIm+SDxiwYtI6ocC3mb9V/t5kvZ+6XQ0=
|
||||||
|
github.com/go-i2p/logger v0.0.1/go.mod h1:te7Zj3g3oMeIl8uBXAgO62UKmZ6m6kHRNg1Mm+X8Hzk=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||||
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
|
||||||
|
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
|
||||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ func TestSessionSendMessage(t *testing.T) {
|
|||||||
payload := NewStream([]byte("test message"))
|
payload := NewStream([]byte("test message"))
|
||||||
|
|
||||||
// Test message sending (should not panic)
|
// Test message sending (should not panic)
|
||||||
session.SendMessage(testDest, PROTOCOL_STREAMING, 1234, 5678, payload, 123456)
|
// Using protocol=6 as test value (not I2CP-defined, represents application-level protocol)
|
||||||
|
session.SendMessage(testDest, 6, 1234, 5678, payload, 123456)
|
||||||
|
|
||||||
// Verify no immediate errors (actual sending requires router connection)
|
// Verify no immediate errors (actual sending requires router connection)
|
||||||
}
|
}
|
||||||
@@ -112,16 +113,18 @@ func TestSessionDispatchMessage(t *testing.T) {
|
|||||||
session := NewSession(client, callbacks)
|
session := NewSession(client, callbacks)
|
||||||
|
|
||||||
// Test message dispatch
|
// Test message dispatch
|
||||||
|
// Using protocol=17 as test value (not I2CP-defined, represents application-level protocol)
|
||||||
|
const testProtocol uint8 = 17
|
||||||
testPayload := NewStream([]byte("test payload"))
|
testPayload := NewStream([]byte("test payload"))
|
||||||
session.dispatchMessage(PROTOCOL_DATAGRAM, 1111, 2222, testPayload)
|
session.dispatchMessage(testProtocol, 1111, 2222, testPayload)
|
||||||
|
|
||||||
// Verify callback was invoked with correct parameters
|
// Verify callback was invoked with correct parameters
|
||||||
if !callbackInvoked {
|
if !callbackInvoked {
|
||||||
t.Error("Message callback was not invoked")
|
t.Error("Message callback was not invoked")
|
||||||
}
|
}
|
||||||
|
|
||||||
if receivedProtocol != PROTOCOL_DATAGRAM {
|
if receivedProtocol != testProtocol {
|
||||||
t.Errorf("Expected protocol %d, got %d", PROTOCOL_DATAGRAM, receivedProtocol)
|
t.Errorf("Expected protocol %d, got %d", testProtocol, receivedProtocol)
|
||||||
}
|
}
|
||||||
|
|
||||||
if receivedSrcPort != 1111 {
|
if receivedSrcPort != 1111 {
|
||||||
@@ -233,7 +236,8 @@ func TestSessionWithNilCallbacks(t *testing.T) {
|
|||||||
testPayload := NewStream([]byte("test"))
|
testPayload := NewStream([]byte("test"))
|
||||||
|
|
||||||
// These should not panic even with nil callbacks
|
// These should not panic even with nil callbacks
|
||||||
session.dispatchMessage(PROTOCOL_STREAMING, 1, 2, testPayload)
|
// Using protocol=6 as test value (not I2CP-defined, represents application-level protocol)
|
||||||
|
session.dispatchMessage(6, 1, 2, testPayload)
|
||||||
session.dispatchDestination(1, "test", nil)
|
session.dispatchDestination(1, "test", nil)
|
||||||
session.dispatchStatus(I2CP_SESSION_STATUS_CREATED)
|
session.dispatchStatus(I2CP_SESSION_STATUS_CREATED)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user