Fixed ping and return to have next hop IP in previous hop message wrapper
This commit is contained in:
@@ -68,7 +68,7 @@ package client
|
|||||||
// // log.I.Ln(len(ci.Hops))
|
// // log.I.Ln(len(ci.Hops))
|
||||||
// for i := range ci.Hops {
|
// for i := range ci.Hops {
|
||||||
// // progress through the hops in reverse
|
// // progress through the hops in reverse
|
||||||
// rm := &wire.Forward{
|
// rm := &wire.HeaderKey{
|
||||||
// IP: ci.Hops[len(ci.Hops)-i-1].IP,
|
// IP: ci.Hops[len(ci.Hops)-i-1].IP,
|
||||||
// Message: lastMsg,
|
// Message: lastMsg,
|
||||||
// }
|
// }
|
||||||
@@ -76,7 +76,7 @@ package client
|
|||||||
// ep := message.EP{
|
// ep := message.EP{
|
||||||
// To: address.
|
// To: address.
|
||||||
// FromPubKey(ci.Hops[len(ci.Hops)-i-1].Key),
|
// FromPubKey(ci.Hops[len(ci.Hops)-i-1].Key),
|
||||||
// From: cl.Sessions[i].KeyRoller.Next(),
|
// From: cl.Sessions[i].KeySet.Next(),
|
||||||
// Length: len(rmm),
|
// Length: len(rmm),
|
||||||
// Data: rmm,
|
// Data: rmm,
|
||||||
// }
|
// }
|
||||||
@@ -134,7 +134,7 @@ package client
|
|||||||
// t.Error(e)
|
// t.Error(e)
|
||||||
// t.FailNow()
|
// t.FailNow()
|
||||||
// }
|
// }
|
||||||
// var rm *wire.Forward
|
// var rm *wire.HeaderKey
|
||||||
// var msg wire.Message
|
// var msg wire.Message
|
||||||
// if msg, e = wire.Deserialize(f.Data); check(e) {
|
// if msg, e = wire.Deserialize(f.Data); check(e) {
|
||||||
// t.Error(e)
|
// t.Error(e)
|
||||||
|
|||||||
@@ -11,10 +11,9 @@ import (
|
|||||||
// with new credit, and the current state of the encryption.
|
// with new credit, and the current state of the encryption.
|
||||||
type Session struct {
|
type Session struct {
|
||||||
nonce.ID
|
nonce.ID
|
||||||
Remaining uint64
|
Remaining uint64
|
||||||
Forward, Return *address.SendEntry
|
HeaderKey, PayloadKey *address.SendEntry
|
||||||
ReceiveEntry *address.ReceiveEntry
|
*signer.KeySet
|
||||||
KeyRoller *signer.KeySet
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Sessions []*Session
|
type Sessions []*Session
|
||||||
@@ -49,15 +48,15 @@ func (s Sessions) Find(t nonce.ID) (se *Session) {
|
|||||||
//
|
//
|
||||||
// Purchasing a session the seller returns a token, based on a requested data
|
// Purchasing a session the seller returns a token, based on a requested data
|
||||||
// allocation,
|
// allocation,
|
||||||
func NewSession(id nonce.ID, rem uint64, fwd, rtn *address.SendEntry,
|
func NewSession(id nonce.ID, rem uint64, hdr, pld *address.SendEntry,
|
||||||
re *address.ReceiveEntry, kr *signer.KeySet) (s *Session) {
|
kr *signer.KeySet) (s *Session) {
|
||||||
|
|
||||||
s = &Session{
|
s = &Session{
|
||||||
ID: id,
|
ID: id,
|
||||||
Remaining: rem,
|
Remaining: rem,
|
||||||
Forward: fwd,
|
HeaderKey: hdr,
|
||||||
ReceiveEntry: re,
|
PayloadKey: pld,
|
||||||
KeyRoller: kr,
|
KeySet: kr,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -78,11 +77,3 @@ func (s *Session) SubtractBytes(b uint64) bool {
|
|||||||
s.Remaining -= b
|
s.Remaining -= b
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) SetSendEntry(se *address.SendEntry) {
|
|
||||||
s.Forward = se
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Session) SetReceiveEntry(re *address.ReceiveEntry) {
|
|
||||||
s.ReceiveEntry = re
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/Indra-Labs/indra/pkg/key/prv"
|
"github.com/Indra-Labs/indra/pkg/key/prv"
|
||||||
"github.com/Indra-Labs/indra/pkg/key/pub"
|
"github.com/Indra-Labs/indra/pkg/key/pub"
|
||||||
|
"github.com/Indra-Labs/indra/pkg/nonce"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SendEntry tracks the received signing keys to be used for messages with a
|
// SendEntry tracks the received signing keys to be used for messages with a
|
||||||
@@ -91,15 +92,16 @@ func (sc *SendCache) Delete(k pub.Bytes) (e error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReceiveEntry tracks the details of a receiver key and their related IP
|
// ReceiveEntry tracks the details of a receiver key and their ID.
|
||||||
// address.
|
|
||||||
type ReceiveEntry struct {
|
type ReceiveEntry struct {
|
||||||
|
nonce.ID
|
||||||
*Receiver
|
*Receiver
|
||||||
time.Time
|
time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReceiveEntry(priv *prv.Key) *ReceiveEntry {
|
func NewReceiveEntry(priv *prv.Key) *ReceiveEntry {
|
||||||
return &ReceiveEntry{
|
return &ReceiveEntry{
|
||||||
|
ID: nonce.NewID(),
|
||||||
Receiver: NewReceiver(priv),
|
Receiver: NewReceiver(priv),
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
}
|
}
|
||||||
@@ -128,7 +130,7 @@ func (rc *ReceiveCache) Len() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rc *ReceiveCache) Add(r *Receiver) {
|
func (rc *ReceiveCache) Add(r *Receiver) {
|
||||||
re := &ReceiveEntry{Receiver: r, Time: time.Now()}
|
re := NewReceiveEntry(r.Key)
|
||||||
rc.ReceiveEntries = append(rc.ReceiveEntries, re)
|
rc.ReceiveEntries = append(rc.ReceiveEntries, re)
|
||||||
rc.Index = append(rc.Index, pub.Derive(r.Key).ToBytes())
|
rc.Index = append(rc.Index, pub.Derive(r.Key).ToBytes())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ var (
|
|||||||
type Node struct {
|
type Node struct {
|
||||||
nonce.ID
|
nonce.ID
|
||||||
net.IP
|
net.IP
|
||||||
Forward, Return *pub.Key
|
HeaderKey, PayloadKey *pub.Key
|
||||||
ifc.Transport
|
ifc.Transport
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,11 +34,11 @@ type Node struct {
|
|||||||
func New(ip net.IP, fwd, rtn *pub.Key, tpt ifc.Transport) (n *Node, id nonce.ID) {
|
func New(ip net.IP, fwd, rtn *pub.Key, tpt ifc.Transport) (n *Node, id nonce.ID) {
|
||||||
id = nonce.NewID()
|
id = nonce.NewID()
|
||||||
n = &Node{
|
n = &Node{
|
||||||
ID: id,
|
ID: id,
|
||||||
IP: ip,
|
IP: ip,
|
||||||
Transport: tpt,
|
Transport: tpt,
|
||||||
Forward: fwd,
|
HeaderKey: fwd,
|
||||||
Return: rtn,
|
PayloadKey: rtn,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ type OnionSkins []Onion
|
|||||||
func (o OnionSkins) Message(to *address.Sender, from *prv.Key) OnionSkins {
|
func (o OnionSkins) Message(to *address.Sender, from *prv.Key) OnionSkins {
|
||||||
return append(o, &Message{To: to, From: from})
|
return append(o, &Message{To: to, From: from})
|
||||||
}
|
}
|
||||||
func (o OnionSkins) Confirmation(ciph sha256.Hash, id nonce.ID) OnionSkins {
|
func (o OnionSkins) Confirmation(id nonce.ID) OnionSkins {
|
||||||
return append(o, &Confirmation{Cipher: ciph, ID: id})
|
return append(o, &Confirmation{ID: id})
|
||||||
}
|
}
|
||||||
func (o OnionSkins) Forward(ip net.IP) OnionSkins {
|
func (o OnionSkins) Forward(ip net.IP) OnionSkins {
|
||||||
return append(o, &Forward{IP: ip})
|
return append(o, &Forward{IP: ip})
|
||||||
|
|||||||
@@ -19,17 +19,18 @@ import (
|
|||||||
// an increment of their liveness score. By using this scheme, when nodes are
|
// an increment of their liveness score. By using this scheme, when nodes are
|
||||||
// offline their scores will fall to zero after a time whereas live nodes will
|
// offline their scores will fall to zero after a time whereas live nodes will
|
||||||
// have steadily increasing scores from successful pings.
|
// have steadily increasing scores from successful pings.
|
||||||
func Ping(ciph sha256.Hash, id nonce.ID, nodes [3]node.Node,
|
func Ping(id nonce.ID, client node.Node, hop [3]node.Node,
|
||||||
set signer.KeySet) Onion {
|
set signer.KeySet) Onion {
|
||||||
|
|
||||||
return OnionSkins{}.
|
return OnionSkins{}.
|
||||||
Message(address.FromPubKey(nodes[0].Forward), set.Next()).
|
Message(address.FromPubKey(hop[0].HeaderKey), set.Next()).
|
||||||
Forward(nodes[0].IP).
|
Forward(hop[1].IP).
|
||||||
Message(address.FromPubKey(nodes[1].Forward), set.Next()).
|
Message(address.FromPubKey(hop[1].HeaderKey), set.Next()).
|
||||||
Forward(nodes[1].IP).
|
Forward(hop[2].IP).
|
||||||
Message(address.FromPubKey(nodes[2].Forward), set.Next()).
|
Message(address.FromPubKey(hop[2].HeaderKey), set.Next()).
|
||||||
Forward(nodes[2].IP).
|
Forward(client.IP).
|
||||||
Confirmation(ciph, id).
|
Message(address.FromPubKey(client.HeaderKey), set.Next()).
|
||||||
|
Confirmation(id).
|
||||||
Assemble()
|
Assemble()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,20 +47,26 @@ func Ping(ciph sha256.Hash, id nonce.ID, nodes [3]node.Node,
|
|||||||
// This message's last layer is a Confirmation, which allows the client to know
|
// This message's last layer is a Confirmation, which allows the client to know
|
||||||
// that the key was successfully delivered to the Return relays that will be
|
// that the key was successfully delivered to the Return relays that will be
|
||||||
// used in the Purchase.
|
// used in the Purchase.
|
||||||
func SendReturn(id nonce.ID, ciph sha256.Hash, hdr, pld *prv.Key,
|
//
|
||||||
nodes [5]node.Node, set signer.KeySet) Onion {
|
// The first hop (0) is the destination of the first layer, 1 is second, 2 is
|
||||||
|
// the return relay, 3 is the first return, 4 is the second return, and client
|
||||||
|
// is the client.
|
||||||
|
func SendReturn(idCipher sha256.Hash, id nonce.ID, hdr, pld *prv.Key,
|
||||||
|
client node.Node, hop [5]node.Node, set signer.KeySet) Onion {
|
||||||
|
|
||||||
return OnionSkins{}.
|
return OnionSkins{}.
|
||||||
Message(address.FromPubKey(nodes[0].Forward), set.Next()).
|
Message(address.FromPubKey(hop[0].HeaderKey), set.Next()).
|
||||||
Forward(nodes[0].IP).
|
Forward(hop[1].IP).
|
||||||
Message(address.FromPubKey(nodes[1].Forward), set.Next()).
|
Message(address.FromPubKey(hop[1].HeaderKey), set.Next()).
|
||||||
Forward(nodes[1].IP).
|
Forward(hop[2].IP).
|
||||||
Message(address.FromPubKey(nodes[2].Forward), set.Next()).
|
Message(address.FromPubKey(hop[2].HeaderKey), set.Next()).
|
||||||
Cipher(hdr, pld).
|
Cipher(hdr, pld).
|
||||||
Message(address.FromPubKey(nodes[3].Forward), set.Next()).
|
Forward(hop[3].IP).
|
||||||
Forward(nodes[1].IP).
|
Message(address.FromPubKey(hop[3].HeaderKey), set.Next()).
|
||||||
Message(address.FromPubKey(nodes[4].Forward), set.Next()).
|
Forward(hop[4].IP).
|
||||||
Forward(nodes[2].IP).
|
Message(address.FromPubKey(hop[4].HeaderKey), set.Next()).
|
||||||
Confirmation(ciph, id).
|
Forward(client.IP).
|
||||||
|
Message(address.FromPubKey(client.HeaderKey), set.Next()).
|
||||||
|
Confirmation(id).
|
||||||
Assemble()
|
Assemble()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package wire
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/aes"
|
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
@@ -114,7 +113,6 @@ func (on *Message) Encode(o slice.Bytes, c *slice.Cursor) {
|
|||||||
// randomly selected, so they will generally be a much smaller subset versus the
|
// randomly selected, so they will generally be a much smaller subset versus the
|
||||||
// current full set of Session s currently open.
|
// current full set of Session s currently open.
|
||||||
type Confirmation struct {
|
type Confirmation struct {
|
||||||
Cipher sha256.Hash
|
|
||||||
nonce.ID
|
nonce.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,13 +126,8 @@ func (cf *Confirmation) Len() int {
|
|||||||
|
|
||||||
func (cf *Confirmation) Encode(o slice.Bytes, c *slice.Cursor) {
|
func (cf *Confirmation) Encode(o slice.Bytes, c *slice.Cursor) {
|
||||||
copy(o[*c:c.Inc(MagicLen)], ConfirmationMagic)
|
copy(o[*c:c.Inc(MagicLen)], ConfirmationMagic)
|
||||||
// Generate block cipher from confirmation Cipher.
|
|
||||||
block, _ := aes.NewCipher(cf.Cipher[:])
|
|
||||||
start, end := *c, c.Inc(nonce.IDLen)
|
|
||||||
// Copy in the ID.
|
// Copy in the ID.
|
||||||
copy(o[start:end], cf.ID[:])
|
copy(o[*c:c.Inc(nonce.IDLen)], cf.ID[:])
|
||||||
// Encrypt the ID to the cipher.
|
|
||||||
ciph.Encipher(block, nonce.New(), o[start:end])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forward is just an IP address and a wrapper for another message.
|
// Forward is just an IP address and a wrapper for another message.
|
||||||
@@ -324,10 +317,10 @@ func (se *Session) Len() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (se *Session) Encode(o slice.Bytes, c *slice.Cursor) {
|
func (se *Session) Encode(o slice.Bytes, c *slice.Cursor) {
|
||||||
fwd, rtn := se.HeaderKey.ToBytes(), se.PayloadKey.ToBytes()
|
hdr, pld := se.HeaderKey.ToBytes(), se.PayloadKey.ToBytes()
|
||||||
copy(o[*c:c.Inc(MagicLen)], SessionMagic)
|
copy(o[*c:c.Inc(MagicLen)], SessionMagic)
|
||||||
copy(o[*c:c.Inc(pub.KeyLen)], fwd[:])
|
copy(o[*c:c.Inc(pub.KeyLen)], hdr[:])
|
||||||
copy(o[*c:c.Inc(pub.KeyLen)], rtn[:])
|
copy(o[*c:c.Inc(pub.KeyLen)], pld[:])
|
||||||
se.Onion.Encode(o, c)
|
se.Onion.Encode(o, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ var (
|
|||||||
// GitRef is the gitref, as in refs/heads/branchname.
|
// GitRef is the gitref, as in refs/heads/branchname.
|
||||||
GitRef = "refs/heads/main"
|
GitRef = "refs/heads/main"
|
||||||
// ParentGitCommit is the commit hash of the parent HEAD.
|
// ParentGitCommit is the commit hash of the parent HEAD.
|
||||||
ParentGitCommit = "ac3e6aaf8f848db2fb18df2b9e6e02c0e0eb2934"
|
ParentGitCommit = "61bd600f319bb33fcb56488ca715a812e36c66a0"
|
||||||
// BuildTime stores the time when the current binary was built.
|
// BuildTime stores the time when the current binary was built.
|
||||||
BuildTime = "2022-12-20T11:11:58Z"
|
BuildTime = "2022-12-20T12:17:55Z"
|
||||||
// SemVer lists the (latest) git tag on the build.
|
// SemVer lists the (latest) git tag on the build.
|
||||||
SemVer = "v0.0.193"
|
SemVer = "v0.0.194"
|
||||||
// PathBase is the path base returned from runtime caller.
|
// PathBase is the path base returned from runtime caller.
|
||||||
PathBase = "/home/loki/src/github.com/Indra-Labs/indra/"
|
PathBase = "/home/loki/src/github.com/Indra-Labs/indra/"
|
||||||
// Major is the major number from the tag.
|
// Major is the major number from the tag.
|
||||||
@@ -25,7 +25,7 @@ var (
|
|||||||
// Minor is the minor number from the tag.
|
// Minor is the minor number from the tag.
|
||||||
Minor = 0
|
Minor = 0
|
||||||
// Patch is the patch version number from the tag.
|
// Patch is the patch version number from the tag.
|
||||||
Patch = 193
|
Patch = 194
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version returns a pretty printed version information string.
|
// Version returns a pretty printed version information string.
|
||||||
|
|||||||
Reference in New Issue
Block a user