sketching out node receive handler

This commit is contained in:
David Vennik
2022-12-28 10:03:58 +00:00
parent 48444a0a62
commit aeae237ae3
4 changed files with 116 additions and 8 deletions

View File

@@ -9,6 +9,21 @@ import (
"github.com/Indra-Labs/indra/pkg/key/prv"
"github.com/Indra-Labs/indra/pkg/key/pub"
"github.com/Indra-Labs/indra/pkg/node"
"github.com/Indra-Labs/indra/pkg/slice"
"github.com/Indra-Labs/indra/pkg/types"
"github.com/Indra-Labs/indra/pkg/wire"
"github.com/Indra-Labs/indra/pkg/wire/cipher"
"github.com/Indra-Labs/indra/pkg/wire/confirmation"
"github.com/Indra-Labs/indra/pkg/wire/delay"
"github.com/Indra-Labs/indra/pkg/wire/exit"
"github.com/Indra-Labs/indra/pkg/wire/forward"
"github.com/Indra-Labs/indra/pkg/wire/layer"
"github.com/Indra-Labs/indra/pkg/wire/noop"
"github.com/Indra-Labs/indra/pkg/wire/purchase"
"github.com/Indra-Labs/indra/pkg/wire/reply"
"github.com/Indra-Labs/indra/pkg/wire/response"
"github.com/Indra-Labs/indra/pkg/wire/session"
"github.com/Indra-Labs/indra/pkg/wire/token"
log2 "github.com/cybriq/proc/pkg/log"
"github.com/cybriq/qu"
)
@@ -50,10 +65,90 @@ out:
case <-c.C.Wait():
c.Cleanup()
break out
case msg := <-c.Node.Receive():
case b := <-c.Node.Receive():
// process received message
_ = msg
var onion types.Onion
var e error
cursor := slice.NewCursor()
if onion, e = wire.PeelOnion(b, cursor); check(e) {
break
}
switch on := onion.(type) {
case *cipher.OnionSkin:
// This either is in a forward only SendKeys
// message or we are the buyer and these are our
// session keys.
break
case *confirmation.OnionSkin:
// This will be an 8 byte nonce that confirms a
// message passed, ping and cipher onions return
// these, as they are pure forward messages that
// send a message one way and the confirmation
// is the acknowledgement.
break
case *delay.OnionSkin:
break
case *exit.OnionSkin:
// payload is forwarded to a local port and the
// response is forwarded back with a reply
// header.
break
case *forward.OnionSkin:
// forward the whole buffer received onwards.
// Usually there will be an OnionSkin under this
// which will be unwrapped by the receiver.
if on.AddrPort.String() == c.Node.AddrPort.String() {
// it is for us, we want to unwrap the
// next part.
} else {
// we need to forward this message onion.
}
break
case *layer.OnionSkin:
// this is probably an encrypted layer for us.
break
case *noop.OnionSkin:
// this won't happen normally
break
case *purchase.OnionSkin:
// Purchase requires a return of arbitrary data.
break
case *reply.OnionSkin:
// Reply means another OnionSkin is coming and
// the payload encryption uses the Payload key.
break
case *response.OnionSkin:
// Response is a payload from an exit message.
break
case *session.OnionSkin:
// Session is returned from a Purchase message
// in the reply layers.
//
// Session has a nonce.ID that is given in the
// last layer of a LN sphinx Bolt 4 onion routed
// payment path that will cause the seller to
// activate the accounting onion the two keys it
// sent back with the nonce.
break
case *token.OnionSkin:
// not really sure if we are using these.
break
default:
log.I.S("unrecognised packet", b)
}
}
}
}

View File

@@ -1,6 +1,15 @@
package client
import (
"testing"
)
func TestNew(t *testing.T) {
}
//
// func TestClient_GenerateCircuit(t *testing.T) {
// var nodes node.Nodes
// var ids []nonce.ID

View File

@@ -3,6 +3,7 @@ package session
import (
"github.com/Indra-Labs/indra"
"github.com/Indra-Labs/indra/pkg/key/pub"
"github.com/Indra-Labs/indra/pkg/nonce"
"github.com/Indra-Labs/indra/pkg/slice"
"github.com/Indra-Labs/indra/pkg/types"
"github.com/Indra-Labs/indra/pkg/wire/magicbytes"
@@ -31,6 +32,7 @@ var (
// their generated private key which produces the public key that is placed in
// the header.
type OnionSkin struct {
nonce.ID
HeaderKey, PayloadKey *pub.Key
types.Onion
}
@@ -38,12 +40,13 @@ type OnionSkin struct {
func (x *OnionSkin) Inner() types.Onion { return x.Onion }
func (x *OnionSkin) Insert(o types.Onion) { x.Onion = o }
func (x *OnionSkin) Len() int {
return magicbytes.Len + pub.KeyLen*2 + x.Onion.Len()
return magicbytes.Len + pub.KeyLen*2 + nonce.IDLen + x.Onion.Len()
}
func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
hdr, pld := x.HeaderKey.ToBytes(), x.PayloadKey.ToBytes()
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
copy(b[*c:c.Inc(nonce.IDLen)], x.ID[:])
copy(b[*c:c.Inc(pub.KeyLen)], hdr[:])
copy(b[*c:c.Inc(pub.KeyLen)], pld[:])
x.Onion.Encode(b, c)
@@ -53,6 +56,7 @@ func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen-magicbytes.Len {
return magicbytes.TooShort(len(b[*c:]), MinLen-magicbytes.Len, string(Magic))
}
copy(x.ID[:], b[*c:c.Inc(nonce.IDLen)])
if x.HeaderKey, e = pub.FromBytes(b[*c:c.Inc(pub.KeyLen)]); check(e) {
return
}

View File

@@ -10,19 +10,19 @@ var (
// GitRef is the gitref, as in refs/heads/branchname.
GitRef = "refs/heads/main"
// ParentGitCommit is the commit hash of the parent HEAD.
ParentGitCommit = "254cbece5f3af57d09f0e9bffcb8eb2e30e4b000"
ParentGitCommit = "493e661bd056e6c6d21eab841dddea39788d62aa"
// BuildTime stores the time when the current binary was built.
BuildTime = "2022-12-28T09:23:35Z"
BuildTime = "2022-12-28T10:03:58Z"
// SemVer lists the (latest) git tag on the build.
SemVer = "v0.0.251"
SemVer = "v0.0.252"
// PathBase is the path base returned from runtime caller.
PathBase = "/home/lyo/Seafile/Git/indra-labs/indra/"
PathBase = "/home/loki/src/github.com/Indra-Labs/indra/"
// Major is the major number from the tag.
Major = 0
// Minor is the minor number from the tag.
Minor = 0
// Patch is the patch version number from the tag.
Patch = 251
Patch = 252
)
// Version returns a pretty printed version information string.