diff --git a/lib/common/certificate_test.go b/lib/common/certificate_test.go index bfd02d9..b22827e 100644 --- a/lib/common/certificate_test.go +++ b/lib/common/certificate_test.go @@ -1,6 +1,8 @@ package common -import "testing" +import ( + "testing" +) func TestCertificateTypeIsFirstByte(t *testing.T) { bytes := []byte{0x03, 0x00, 0x00} diff --git a/lib/common/date.go b/lib/common/date.go index 07d0534..fddbac2 100644 --- a/lib/common/date.go +++ b/lib/common/date.go @@ -1,5 +1,11 @@ package common +/* +I2P Date +https://geti2p.net/en/docs/spec/common-structures#type_Date +Accurate for version 0.9.24 +*/ + import ( "time" ) diff --git a/lib/common/date_test.go b/lib/common/date_test.go index 3d3ef0e..7e0a8e0 100644 --- a/lib/common/date_test.go +++ b/lib/common/date_test.go @@ -1,6 +1,8 @@ package common -import "testing" +import ( + "testing" +) func TestTimeFromMiliseconds(t *testing.T) { next_day := Date{0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5c, 0x00} diff --git a/lib/common/destination.go b/lib/common/destination.go index 783e739..1c2bbca 100644 --- a/lib/common/destination.go +++ b/lib/common/destination.go @@ -1,5 +1,13 @@ package common +/* +I2P Destination +https://geti2p.net/en/docs/spec/common-structures#struct_Destination +Accurate for version 0.9.24 + +Identical to KeysAndCert +*/ + import ( "github.com/bounce-chat/go-i2p/lib/common/base32" "github.com/bounce-chat/go-i2p/lib/common/base64" diff --git a/lib/common/integer.go b/lib/common/integer.go index ed1c934..5d8e2df 100644 --- a/lib/common/integer.go +++ b/lib/common/integer.go @@ -1,5 +1,11 @@ package common +/* +I2P Integer +https://geti2p.net/en/docs/spec/common-structures#type_Integer +Accurate for version 0.9.24 +*/ + import ( "encoding/binary" ) diff --git a/lib/common/key_certificate.go b/lib/common/key_certificate.go index e1ca17a..aceb874 100644 --- a/lib/common/key_certificate.go +++ b/lib/common/key_certificate.go @@ -1,5 +1,11 @@ package common +/* +I2P Key Certificate +https://geti2p.net/en/docs/spec/common-structures#type_Certificate +Accurate for version 0.9.24 +*/ + import ( "errors" "github.com/bounce-chat/go-i2p/lib/crypto" diff --git a/lib/common/lease.go b/lib/common/lease.go index bfc62f2..38b9d1f 100644 --- a/lib/common/lease.go +++ b/lib/common/lease.go @@ -1,23 +1,67 @@ package common +/* +I2P Lease +https://geti2p.net/en/docs/spec/common-structures#struct_Lease +Accurate for version 0.9.24 + ++----+----+----+----+----+----+----+----+ +| tunnel_gw | ++ + +| | ++ + +| | ++ + +| | ++----+----+----+----+----+----+----+----+ +| tunnel_id | end_date ++----+----+----+----+----+----+----+----+ + | ++----+----+----+----+ + +tunnel_gw :: Hash of the RouterIdentity of the tunnel gateway + length -> 32 bytes + +tunnel_id :: TunnelId + length -> 4 bytes + +end_date :: Date + length -> 8 bytes +*/ + import ( "github.com/bounce-chat/go-i2p/lib/tunnel" ) -type Lease [44]byte +const ( + LEASE_SIZE = 44 + LEASE_HASH_SIZE = 32 + LEASE_TUNNEL_ID_SIZE = 4 +) -func (lease Lease) TunnelGateway() (h Hash) { - copy(lease[:32], h[:]) +type Lease [LEASE_SIZE]byte + +// +// Return the first 32 bytes of the Lease as a Hash. +// +func (lease Lease) TunnelGateway() (hash Hash) { + copy(hash[:], lease[:LEASE_HASH_SIZE]) return } +// +// Parse the TunnelID Integer in the Lease. +// func (lease Lease) TunnelID() tunnel.TunnelID { return tunnel.TunnelID( - Integer(lease[32:36]), + Integer(lease[LEASE_HASH_SIZE : LEASE_HASH_SIZE+LEASE_TUNNEL_ID_SIZE]), ) } -func (lease Lease) Date() (d Date) { - copy(lease[36:], d[:]) +// +// Return the Date inside the Lease. +// +func (lease Lease) Date() (date Date) { + copy(date[:], lease[LEASE_HASH_SIZE+LEASE_TUNNEL_ID_SIZE:]) return } diff --git a/lib/common/string_test.go b/lib/common/string_test.go index 90554f3..ae97b71 100644 --- a/lib/common/string_test.go +++ b/lib/common/string_test.go @@ -1,6 +1,8 @@ package common -import "testing" +import ( + "testing" +) func TestStringReportsCorrectLength(t *testing.T) { str_len, err := String([]byte{0x02, 0x00, 0x00}).Length()