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
import "testing"
import (
"testing"
)
func TestCertificateTypeIsFirstByte(t *testing.T) {
bytes := []byte{0x03, 0x00, 0x00}

View File

@ -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"
)

View File

@ -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}

View File

@ -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"

View File

@ -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"
)

View File

@ -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"

View File

@ -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
}

View File

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