eliminate redundant copy for onions

This commit is contained in:
David Vennik
2022-12-27 20:16:41 +00:00
parent 111ac63b47
commit 652fa80703
3 changed files with 20 additions and 28 deletions

View File

@@ -88,15 +88,11 @@ func SendKeys(id nonce.ID, hdr, pld *pub.Key,
func SendPurchase(nBytes uint64, client *node.Node,
hop [5]*node.Node, set *signer.KeySet) types.Onion {
var replies [3]*prv.Key
for i := range replies {
replies[i] = set.Next()
}
var prvs [3]*prv.Key
for i := range prvs {
prvs[i] = set.Next()
}
var pubs [3]*pub.Key
prvs[0] = replies[2]
prvs[1] = replies[1]
prvs[2] = replies[0]
pubs[0] = client.PayloadKey
pubs[1] = hop[4].PayloadKey
pubs[2] = hop[3].PayloadKey
@@ -109,11 +105,11 @@ func SendPurchase(nBytes uint64, client *node.Node,
OnionSkin(address.FromPubKey(hop[2].HeaderKey), set.Next()).
Purchase(nBytes, prvs, pubs).
Reply(hop[3].AddrPort).
OnionSkin(address.FromPubKey(hop[3].HeaderKey), replies[0]).
OnionSkin(address.FromPubKey(hop[3].HeaderKey), prvs[0]).
Reply(hop[4].AddrPort).
OnionSkin(address.FromPubKey(hop[4].HeaderKey), replies[1]).
OnionSkin(address.FromPubKey(hop[4].HeaderKey), prvs[1]).
Reply(client.AddrPort).
OnionSkin(address.FromPubKey(client.HeaderKey), replies[2]).
OnionSkin(address.FromPubKey(client.HeaderKey), prvs[2]).
Assemble()
}
@@ -138,16 +134,12 @@ func SendPurchase(nBytes uint64, client *node.Node,
func SendExit(payload slice.Bytes, port uint16, client *node.Node,
hop [5]*node.Node, set *signer.KeySet) types.Onion {
var replies [3]*prv.Key
for i := range replies {
replies[i] = set.Next()
var prvs [3]*prv.Key
for i := range prvs {
prvs[i] = set.Next()
}
var prvs [3]*prv.Key
var pubs [3]*pub.Key
prvs[0] = replies[2]
prvs[1] = replies[1]
prvs[2] = replies[0]
pubs[0] = client.PayloadKey
pubs[1] = hop[4].PayloadKey
pubs[2] = hop[3].PayloadKey
@@ -160,10 +152,10 @@ func SendExit(payload slice.Bytes, port uint16, client *node.Node,
OnionSkin(address.FromPubKey(hop[2].HeaderKey), set.Next()).
Exit(port, prvs, pubs, payload).
Reply(hop[3].AddrPort).
OnionSkin(address.FromPubKey(hop[3].HeaderKey), replies[0]).
OnionSkin(address.FromPubKey(hop[3].HeaderKey), prvs[0]).
Reply(hop[4].AddrPort).
OnionSkin(address.FromPubKey(hop[4].HeaderKey), replies[1]).
OnionSkin(address.FromPubKey(hop[4].HeaderKey), prvs[1]).
Reply(client.AddrPort).
OnionSkin(address.FromPubKey(client.HeaderKey), replies[2]).
OnionSkin(address.FromPubKey(client.HeaderKey), prvs[2]).
Assemble()
}

View File

@@ -399,7 +399,7 @@ func TestSendPurchase(t *testing.T) {
// Reply(hop[4].AddrPort).
rp2 := PeelReply(t, b, c)
if rp2.AddrPort.String() != hop[4].AddrPort.String() {
t.Errorf("failed to retrieve first reply hop")
t.Errorf("failed to retrieve second reply hop")
t.FailNow()
}
@@ -409,7 +409,7 @@ func TestSendPurchase(t *testing.T) {
// Reply(client.AddrPort).
rp3 := PeelReply(t, b, c)
if rp3.AddrPort.String() != client.AddrPort.String() {
t.Errorf("failed to retrieve first reply hop")
t.Errorf("failed to retrieve third reply hop")
t.FailNow()
}
@@ -503,7 +503,7 @@ func TestSendExit(t *testing.T) {
// Reply(hop[4].AddrPort).
rp2 := PeelReply(t, b, c)
if rp2.AddrPort.String() != hop[4].AddrPort.String() {
t.Errorf("failed to retrieve first reply hop")
t.Errorf("failed to retrieve second reply hop")
t.FailNow()
}
@@ -513,7 +513,7 @@ func TestSendExit(t *testing.T) {
// Reply(client.AddrPort).
rp3 := PeelReply(t, b, c)
if rp3.AddrPort.String() != client.AddrPort.String() {
t.Errorf("failed to retrieve first reply hop")
t.Errorf("failed to retrieve third reply hop")
t.FailNow()
}

View File

@@ -10,11 +10,11 @@ var (
// GitRef is the gitref, as in refs/heads/branchname.
GitRef = "refs/heads/main"
// ParentGitCommit is the commit hash of the parent HEAD.
ParentGitCommit = "c0f78dd95dffe2d6bebe6e219bc6954ea10ab5f7"
ParentGitCommit = "470b3ce861bb82711bea6370f9f53b63be60e502"
// BuildTime stores the time when the current binary was built.
BuildTime = "2022-12-27T18:05:32Z"
BuildTime = "2022-12-27T20:16:41Z"
// SemVer lists the (latest) git tag on the build.
SemVer = "v0.0.246"
SemVer = "v0.0.247"
// PathBase is the path base returned from runtime caller.
PathBase = "/home/loki/src/github.com/Indra-Labs/indra/"
// Major is the major number from the tag.
@@ -22,7 +22,7 @@ var (
// Minor is the minor number from the tag.
Minor = 0
// Patch is the patch version number from the tag.
Patch = 246
Patch = 247
)
// Version returns a pretty printed version information string.