small fixes, lease

This commit is contained in:
Hayden Parker
2016-02-14 23:10:37 -08:00
parent f9706700a1
commit 9d6560b94d
8 changed files with 85 additions and 9 deletions

View File

@ -1,6 +1,8 @@
package common package common
import "testing" import (
"testing"
)
func TestCertificateTypeIsFirstByte(t *testing.T) { func TestCertificateTypeIsFirstByte(t *testing.T) {
bytes := []byte{0x03, 0x00, 0x00} bytes := []byte{0x03, 0x00, 0x00}

View File

@ -1,5 +1,11 @@
package common package common
/*
I2P Date
https://geti2p.net/en/docs/spec/common-structures#type_Date
Accurate for version 0.9.24
*/
import ( import (
"time" "time"
) )

View File

@ -1,6 +1,8 @@
package common package common
import "testing" import (
"testing"
)
func TestTimeFromMiliseconds(t *testing.T) { func TestTimeFromMiliseconds(t *testing.T) {
next_day := Date{0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5c, 0x00} next_day := Date{0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5c, 0x00}

View File

@ -1,5 +1,13 @@
package common package common
/*
I2P Destination
https://geti2p.net/en/docs/spec/common-structures#struct_Destination
Accurate for version 0.9.24
Identical to KeysAndCert
*/
import ( import (
"github.com/bounce-chat/go-i2p/lib/common/base32" "github.com/bounce-chat/go-i2p/lib/common/base32"
"github.com/bounce-chat/go-i2p/lib/common/base64" "github.com/bounce-chat/go-i2p/lib/common/base64"

View File

@ -1,5 +1,11 @@
package common package common
/*
I2P Integer
https://geti2p.net/en/docs/spec/common-structures#type_Integer
Accurate for version 0.9.24
*/
import ( import (
"encoding/binary" "encoding/binary"
) )

View File

@ -1,5 +1,11 @@
package common package common
/*
I2P Key Certificate
https://geti2p.net/en/docs/spec/common-structures#type_Certificate
Accurate for version 0.9.24
*/
import ( import (
"errors" "errors"
"github.com/bounce-chat/go-i2p/lib/crypto" "github.com/bounce-chat/go-i2p/lib/crypto"

View File

@ -1,23 +1,67 @@
package common 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 ( import (
"github.com/bounce-chat/go-i2p/lib/tunnel" "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) { type Lease [LEASE_SIZE]byte
copy(lease[:32], h[:])
//
// Return the first 32 bytes of the Lease as a Hash.
//
func (lease Lease) TunnelGateway() (hash Hash) {
copy(hash[:], lease[:LEASE_HASH_SIZE])
return return
} }
//
// Parse the TunnelID Integer in the Lease.
//
func (lease Lease) TunnelID() tunnel.TunnelID { func (lease Lease) TunnelID() tunnel.TunnelID {
return 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 return
} }

View File

@ -1,6 +1,8 @@
package common package common
import "testing" import (
"testing"
)
func TestStringReportsCorrectLength(t *testing.T) { func TestStringReportsCorrectLength(t *testing.T) {
str_len, err := String([]byte{0x02, 0x00, 0x00}).Length() str_len, err := String([]byte{0x02, 0x00, 0x00}).Length()