2016-02-01 01:56:10 -08:00
|
|
|
package common
|
|
|
|
|
2016-02-14 23:10:37 -08:00
|
|
|
/*
|
|
|
|
I2P Lease
|
2016-06-16 23:17:21 -07:00
|
|
|
https://geti2p.net/spec/common-structures#lease
|
2016-02-14 23:10:37 -08:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2016-06-17 21:07:16 -07:00
|
|
|
// Sizes or various components of a Lease
|
2016-02-14 23:10:37 -08:00
|
|
|
const (
|
2021-04-22 23:47:15 -04:00
|
|
|
LEASE_SIZE = 44
|
|
|
|
LEASE_HASH_SIZE = 32
|
|
|
|
LEASE_TUNNEL_ID_SIZE = 4
|
2021-04-22 22:55:32 -04:00
|
|
|
LEASE_TUNNEL_DATE_SIZE = 8
|
2016-02-14 23:10:37 -08:00
|
|
|
)
|
|
|
|
|
2021-04-22 22:55:32 -04:00
|
|
|
type Lease struct {
|
2021-04-22 23:47:15 -04:00
|
|
|
LeaseHash [LEASE_HASH_SIZE]byte
|
2021-04-22 22:55:32 -04:00
|
|
|
TunnelIdent [LEASE_TUNNEL_ID_SIZE]byte
|
2021-04-22 23:47:15 -04:00
|
|
|
TunnelDate [LEASE_TUNNEL_DATE_SIZE]byte
|
2021-04-22 22:55:32 -04:00
|
|
|
}
|
2021-04-22 23:47:15 -04:00
|
|
|
|
2021-04-22 22:55:32 -04:00
|
|
|
//[LEASE_SIZE]byte
|
2016-02-01 01:56:10 -08:00
|
|
|
|
2016-02-14 23:10:37 -08:00
|
|
|
//
|
|
|
|
// Return the first 32 bytes of the Lease as a Hash.
|
|
|
|
//
|
|
|
|
func (lease Lease) TunnelGateway() (hash Hash) {
|
2021-04-22 22:55:32 -04:00
|
|
|
copy(hash[:], lease.LeaseHash[:])
|
2016-02-01 01:56:10 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-02-14 23:10:37 -08:00
|
|
|
//
|
|
|
|
// Parse the TunnelID Integer in the Lease.
|
|
|
|
//
|
2016-09-11 00:20:16 -07:00
|
|
|
func (lease Lease) TunnelID() uint32 {
|
2021-04-22 22:55:32 -04:00
|
|
|
return uint32(Integer(lease.TunnelIdent[:]))
|
2016-02-01 01:56:10 -08:00
|
|
|
}
|
|
|
|
|
2016-02-14 23:10:37 -08:00
|
|
|
//
|
|
|
|
// Return the Date inside the Lease.
|
|
|
|
//
|
|
|
|
func (lease Lease) Date() (date Date) {
|
2021-04-22 22:55:32 -04:00
|
|
|
copy(date[:], lease.TunnelDate[:])
|
2016-02-01 01:56:10 -08:00
|
|
|
return
|
|
|
|
}
|
2021-04-22 22:55:32 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Possibly temporary? Just to make it compile for now
|
|
|
|
//
|
|
|
|
func (lease Lease) Bytes() (bytes []byte) {
|
|
|
|
var r []byte
|
|
|
|
r = append(r, lease.LeaseHash[:]...)
|
|
|
|
r = append(r, lease.TunnelIdent[:]...)
|
|
|
|
r = append(r, lease.TunnelDate[:]...)
|
|
|
|
return r
|
|
|
|
}
|