finish structifying lease, add a stub file for lease2

This commit is contained in:
idk
2021-04-24 18:04:10 -04:00
parent 6de4dde1f2
commit d5266f8980
2 changed files with 54 additions and 8 deletions

View File

@ -37,13 +37,19 @@ const (
LEASE_TUNNEL_DATE_SIZE = 8
)
type Lease struct {
LeaseHash [LEASE_HASH_SIZE]byte
TunnelIdent [LEASE_TUNNEL_ID_SIZE]byte
TunnelDate [LEASE_TUNNEL_DATE_SIZE]byte
type LeaseInterface interface {
TunnelGateway() (hash Hash)
TunnelID() uint32
Date() (date Date)
}
//[LEASE_SIZE]byte
type Lease struct {
LeaseHash Hash //[LEASE_HASH_SIZE]byte
TunnelIdent int //[LEASE_TUNNEL_ID_SIZE]byte
TunnelDate Date //[LEASE_TUNNEL_DATE_SIZE]byte
} //[LEASE_SIZE]byte
var li LeaseInterface = &Lease{}
//
// Return the first 32 bytes of the Lease as a Hash.
@ -54,10 +60,10 @@ func (lease Lease) TunnelGateway() (hash Hash) {
}
//
// Parse the TunnelID Integer in the Lease.
// Return the TunnelID Integer in the Lease.
//
func (lease Lease) TunnelID() uint32 {
return uint32(Integer(lease.TunnelIdent[:]))
return uint32(lease.TunnelIdent)
}
//
@ -74,7 +80,7 @@ func (lease Lease) Date() (date Date) {
func (lease Lease) Bytes() (bytes []byte) {
var r []byte
r = append(r, lease.LeaseHash[:]...)
r = append(r, lease.TunnelIdent[:]...)
r = append(r, IntegerBytes(lease.TunnelIdent)[:]...)
r = append(r, lease.TunnelDate[:]...)
return r
}

40
lib/common/lease2.go Normal file
View File

@ -0,0 +1,40 @@
package common
/*
Lease2
https://geti2p.net/spec/common-structures#lease2
Description
Defines the authorization for a particular tunnel to receive messages targeting a Destination. Same as Lease but with a 4-byte end_date. Used by LeaseSet2. Supported as of 0.9.38; see proposal 123 for more information.
Contents
SHA256 Hash of the RouterIdentity of the gateway router, then the TunnelId, and finally a 4 byte end date.
+----+----+----+----+----+----+----+----+
| 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 :: 4 byte date
length -> 4 bytes
Seconds since the epoch, rolls over in 2106.
Notes
Total size: 40 bytes
JavaDoc: http://echelon.i2p/javadoc/net/i2p/data/Lease2.html
*/