SendKeys working purely by purchased sessions

This commit is contained in:
David Vennik
2023-01-14 22:08:29 +00:00
parent f2672e9ca0
commit 39a2802037
4 changed files with 40 additions and 25 deletions

View File

@@ -37,7 +37,7 @@ var (
type Client struct {
*node.Node
node.Nodes
PendingSessions []nonce.ID
PendingSessions []*node.Session
*confirm.Confirms
ExitHooks response.Hooks
sync.Mutex
@@ -113,6 +113,10 @@ func (cl *Client) FindCloaked(clk cloak.PubKey) (hdr *prv.Key,
return
}
func (cl *Client) GenerateCircuit() {
}
// Cleanup closes and flushes any resources the client opened that require sync
// in order to reopen correctly.
func (cl *Client) Cleanup() {

View File

@@ -21,7 +21,7 @@ func TestPing(t *testing.T) {
const nTotal = 6
clients := make([]*Client, nTotal)
var e error
if clients, e = CreateMockCircuitClients(); check(e) {
if clients, e = CreateMockCircuitClients(true); check(e) {
t.Error(e)
t.FailNow()
}
@@ -62,7 +62,7 @@ func TestSendExit(t *testing.T) {
const nTotal = 6
clients := make([]*Client, nTotal)
var e error
if clients, e = CreateMockCircuitClients(); check(e) {
if clients, e = CreateMockCircuitClients(true); check(e) {
t.Error(e)
t.FailNow()
}
@@ -127,7 +127,7 @@ func TestSendExit(t *testing.T) {
func TestSendKeys(t *testing.T) {
var clients []*Client
var e error
if clients, e = CreateMockCircuitClients(); check(e) {
if clients, e = CreateMockCircuitClients(false); check(e) {
t.Error(e)
t.FailNow()
}
@@ -141,24 +141,31 @@ func TestSendKeys(t *testing.T) {
quit.Q()
t.Error("SendKeys got stuck")
}()
cnf := nonce.NewID()
var sess [5]*session.OnionSkin
var pmt [5]*node.Payment
for i := range clients[1:] {
for i, v := range clients[1:] {
// Create a new payment and drop on the payment channel.
sess[i] = session.New()
pmt[i] = sess[i].ToPayment(1000000)
clients[i+1].PaymentChan <- pmt[i]
clients[0].PendingSessions = append(
clients[0].PendingSessions,
node.NewSession(cnf, v.Node, pmt[i].Amount,
sess[i].Header, sess[i].Payload),
)
}
// Send the keys.
var circuit node.Circuit
for i := range circuit {
circuit[i] = clients[0].Sessions[i+1]
circuit[i] = node.NewSession(pmt[i].ID,
clients[i+1].Node, pmt[i].Amount,
sess[i].Header, sess[i].Payload)
}
var hdr, pld [5]*prv.Key
for i := range hdr {
hdr[i], pld[i] = sess[i].Header, sess[i].Payload
}
cnf := nonce.NewID()
sk := wire.SendKeys(cnf, hdr, pld, clients[0].Node,
circuit, clients[0].KeySet)
clients[0].RegisterConfirmation(func(cf nonce.ID) {

View File

@@ -14,7 +14,9 @@ import (
const nTotal = 6
func CreateMockCircuitClients() (clients []*Client, e error) {
func CreateMockCircuitClients(inclSessions bool) (clients []*Client,
e error) {
clients = make([]*Client, nTotal)
nodes := make([]*node.Node, nTotal)
transports := make([]ifc.Transport, nTotal)
@@ -36,21 +38,23 @@ func CreateMockCircuitClients() (clients []*Client, e error) {
}
clients[i].AddrPort = nodes[i].AddrPort
clients[i].Node = nodes[i]
// create a session for all but the first
if i > 0 {
sessions[i-1] = node.NewSession(nonce.NewID(), nodes[i], math.MaxUint64, nil, nil)
// Add session to node, so it will be able to relay if
// it gets a message with the key.
nodes[i].Sessions = append(nodes[i].Sessions,
sessions[i-1])
nodes[0].Sessions = append(nodes[0].Sessions,
sessions[i-1])
// Normally only the client would have this in its
// nodes, but we are sharing them for simple circuit
// tests. Relays don't use this field, though clients
// can be relays.
nodes[i].Circuit = &node.Circuit{}
nodes[i].Circuit[i-1] = sessions[i-1]
if inclSessions {
// create a session for all but the first
if i > 0 {
sessions[i-1] = node.NewSession(nonce.NewID(), nodes[i], math.MaxUint64, nil, nil)
// Add session to node, so it will be able to relay if
// it gets a message with the key.
nodes[i].Sessions = append(nodes[i].Sessions,
sessions[i-1])
nodes[0].Sessions = append(nodes[0].Sessions,
sessions[i-1])
// Normally only the client would have this in its
// nodes, but we are sharing them for simple circuit
// tests. Relays don't use this field, though clients
// can be relays.
nodes[i].Circuit = &node.Circuit{}
nodes[i].Circuit[i-1] = sessions[i-1]
}
}
}
// Add each node to each other's Nodes except itself, this enables them

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 = "085c068d47046ba31c911c7ca226be6fcf32634b"
ParentGitCommit = "4b314c607788a95aa35d75fc0966816752a51579"
// BuildTime stores the time when the current binary was built.
BuildTime = "2023-01-14T21:15:42Z"
BuildTime = "2023-01-14T22:08:29Z"
// SemVer lists the (latest) git tag on the release.
SemVer = "v0.1.7"
// PathBase is the path base returned from runtime caller.