Purchase Flow test sends out keys

This commit is contained in:
David Vennik
2023-01-07 14:15:17 +00:00
parent f44748b378
commit 04bd7e250e
6 changed files with 49 additions and 47 deletions

View File

@@ -17,6 +17,7 @@ import (
"github.com/indra-labs/indra/pkg/nonce"
"github.com/indra-labs/indra/pkg/session"
"github.com/indra-labs/indra/pkg/slice"
"github.com/indra-labs/indra/pkg/wire"
"github.com/indra-labs/indra/pkg/wire/confirm"
"github.com/indra-labs/indra/pkg/wire/layer"
"github.com/indra-labs/indra/pkg/wire/response"
@@ -92,9 +93,11 @@ func (cl *Client) RegisterConfirmation(hook confirm.Hook,
})
}
func (cl *Client) SendKeys(nodeID nonce.ID) (hdr, pld *prv.Key, hdrPub,
pldPub *pub.Key, id nonce.ID, hook func(cf nonce.ID), e error) {
func (cl *Client) SendKeys(nodeID nonce.ID,
hook func(cf nonce.ID)) (confirmation nonce.ID, hdr, pld *prv.Key,
e error) {
var hdrPub, pldPub *pub.Key
if hdr, e = prv.GenerateKey(); check(e) {
return
}
@@ -105,7 +108,16 @@ func (cl *Client) SendKeys(nodeID nonce.ID) (hdr, pld *prv.Key, hdrPub,
pldPub = pub.Derive(pld)
n := cl.Nodes.FindByID(nodeID)
_ = n
selected := cl.Nodes.Select(SimpleSelector, n, 4)
var hop [5]*node.Node
hop[0], hop[1], hop[2], hop[3], hop[4] =
selected[0], selected[1], selected[2], selected[3], cl.Node
confirmation = nonce.NewID()
os := wire.SendKeys(confirmation, hdrPub, pldPub, cl.Node, hop, cl.KeySet)
cl.RegisterConfirmation(hook, os[len(os)-1].(*confirm.OnionSkin).ID)
o := os.Assemble()
b := wire.EncodeOnion(o)
cl.Send(hop[0].AddrPort, b)
return
}

View File

@@ -6,7 +6,6 @@ import (
"github.com/cybriq/qu"
"github.com/indra-labs/indra/pkg/key/address"
"github.com/indra-labs/indra/pkg/key/pub"
"github.com/indra-labs/indra/pkg/key/signer"
"github.com/indra-labs/indra/pkg/node"
"github.com/indra-labs/indra/pkg/nonce"
@@ -74,37 +73,11 @@ func TestSendKeys(t *testing.T) {
for _, v := range clients {
go v.Start()
}
pn := nonce.NewID()
var ks *signer.KeySet
if _, ks, e = signer.New(); check(e) {
t.Error(e)
t.FailNow()
}
var hop [nTotal - 1]*node.Node
for i := range clients[0].Nodes {
hop[i] = clients[0].Nodes[i]
}
var hdr, pld *pub.Key
if _, _, hdr, pld, e = testutils.GenerateTestKeyPairs(); check(e) {
t.Error(e)
t.FailNow()
}
os := wire.SendKeys(pn, hdr, pld, clients[0].Node, hop, ks)
log.I.S(os)
log.I.S("sending sendkeys with ID", os[len(os)-1].(*confirm.OnionSkin))
quit := qu.T()
clients[0].RegisterConfirmation(func(cf nonce.ID) {
clients[0].SendKeys(clients[0].Nodes[0].ID, func(cf nonce.ID) {
log.I.S("received sendkeys confirmation ID", cf)
quit.Q()
}, os[len(os)-1].(*confirm.OnionSkin).ID)
o := os.Assemble()
b := wire.EncodeOnion(o)
hop[0].Send(b)
// go func() {
// time.Sleep(time.Second * 2)
// quit.Q()
// t.Error("sendkeys got stuck")
// }()
})
<-quit.Wait()
for _, v := range clients {
v.Shutdown()

View File

@@ -1,10 +1,11 @@
package client
import (
"sync"
"testing"
"time"
"github.com/cybriq/qu"
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/nonce"
)
func TestPurchaseFlow(t *testing.T) {
@@ -19,14 +20,28 @@ func TestPurchaseFlow(t *testing.T) {
for _, v := range clients {
go v.Start()
}
quit := qu.T()
go func() {
time.Sleep(time.Second * 3)
quit.Q()
}()
// quit := qu.T()
// go func() {
// time.Sleep(time.Second * 3)
// quit.Q()
// }()
// <-quit.Wait()
selected := clients[0].Nodes.Select(SimpleSelector, clients[1].Node, 4)
_ = selected
<-quit.Wait()
// next to send out keys for the return hops
returnNodes := selected[2:]
var rtnHdr, rtnPld [2]*prv.Key
var confirmation [2]nonce.ID
var wait sync.WaitGroup
for i := range returnNodes {
wait.Add(1)
confirmation[i], rtnHdr[i], rtnPld[i], e = clients[0].
SendKeys(returnNodes[i].ID, func(cf nonce.ID) {
log.I.S("confirmed", cf)
wait.Done()
})
}
log.I.S(confirmation)
wait.Wait()
for _, v := range clients {
v.Shutdown()
}

View File

@@ -72,7 +72,7 @@ func (cl *Client) runner() (out bool) {
func (cl *Client) cipher(on *cipher.OnionSkin, b slice.Bytes, c *slice.Cursor) {
// This either is in a forward only SendKeys message or we are the buyer
// and these are our session keys.
log.I.S(on)
// log.I.S(on)
b = append(b[*c:], slice.NoisePad(int(*c))...)
cl.Node.Send(b)
}

View File

@@ -22,9 +22,11 @@ func SimpleSelector(n node.Nodes, exit *node.Node,
}
// Remove the exit from the list of options.
var nCandidates node.Nodes
for i := range n {
if n[i].ID != exit.ID {
nCandidates = append(nCandidates, n[i])
if exit != nil {
for i := range n {
if n[i].ID != exit.ID {
nCandidates = append(nCandidates, n[i])
}
}
}
// Shuffle the list we made

View File

@@ -10,9 +10,9 @@ var (
// GitRef is the gitref, as in refs/heads/branchname.
GitRef = "refs/heads/protocol"
// ParentGitCommit is the commit hash of the parent HEAD.
ParentGitCommit = "058298ec06a73e055abc8b40cdc67a6c139fb14a"
ParentGitCommit = "b9666fd6f9c68420f0c0b69f3fcac6e336b0dd62"
// BuildTime stores the time when the current binary was built.
BuildTime = "2023-01-07T10:52:23Z"
BuildTime = "2023-01-07T14:15:17Z"
// SemVer lists the (latest) git tag on the release.
SemVer = "v0.1.4"
// PathBase is the path base returned from runtime caller.