SendKeys working purely by purchased sessions
This commit is contained in:
@@ -37,7 +37,7 @@ var (
|
|||||||
type Client struct {
|
type Client struct {
|
||||||
*node.Node
|
*node.Node
|
||||||
node.Nodes
|
node.Nodes
|
||||||
PendingSessions []nonce.ID
|
PendingSessions []*node.Session
|
||||||
*confirm.Confirms
|
*confirm.Confirms
|
||||||
ExitHooks response.Hooks
|
ExitHooks response.Hooks
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
@@ -113,6 +113,10 @@ func (cl *Client) FindCloaked(clk cloak.PubKey) (hdr *prv.Key,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cl *Client) GenerateCircuit() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup closes and flushes any resources the client opened that require sync
|
// Cleanup closes and flushes any resources the client opened that require sync
|
||||||
// in order to reopen correctly.
|
// in order to reopen correctly.
|
||||||
func (cl *Client) Cleanup() {
|
func (cl *Client) Cleanup() {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func TestPing(t *testing.T) {
|
|||||||
const nTotal = 6
|
const nTotal = 6
|
||||||
clients := make([]*Client, nTotal)
|
clients := make([]*Client, nTotal)
|
||||||
var e error
|
var e error
|
||||||
if clients, e = CreateMockCircuitClients(); check(e) {
|
if clients, e = CreateMockCircuitClients(true); check(e) {
|
||||||
t.Error(e)
|
t.Error(e)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ func TestSendExit(t *testing.T) {
|
|||||||
const nTotal = 6
|
const nTotal = 6
|
||||||
clients := make([]*Client, nTotal)
|
clients := make([]*Client, nTotal)
|
||||||
var e error
|
var e error
|
||||||
if clients, e = CreateMockCircuitClients(); check(e) {
|
if clients, e = CreateMockCircuitClients(true); check(e) {
|
||||||
t.Error(e)
|
t.Error(e)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,7 @@ func TestSendExit(t *testing.T) {
|
|||||||
func TestSendKeys(t *testing.T) {
|
func TestSendKeys(t *testing.T) {
|
||||||
var clients []*Client
|
var clients []*Client
|
||||||
var e error
|
var e error
|
||||||
if clients, e = CreateMockCircuitClients(); check(e) {
|
if clients, e = CreateMockCircuitClients(false); check(e) {
|
||||||
t.Error(e)
|
t.Error(e)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
@@ -141,24 +141,31 @@ func TestSendKeys(t *testing.T) {
|
|||||||
quit.Q()
|
quit.Q()
|
||||||
t.Error("SendKeys got stuck")
|
t.Error("SendKeys got stuck")
|
||||||
}()
|
}()
|
||||||
|
cnf := nonce.NewID()
|
||||||
var sess [5]*session.OnionSkin
|
var sess [5]*session.OnionSkin
|
||||||
var pmt [5]*node.Payment
|
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.
|
// Create a new payment and drop on the payment channel.
|
||||||
sess[i] = session.New()
|
sess[i] = session.New()
|
||||||
pmt[i] = sess[i].ToPayment(1000000)
|
pmt[i] = sess[i].ToPayment(1000000)
|
||||||
clients[i+1].PaymentChan <- pmt[i]
|
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.
|
// Send the keys.
|
||||||
var circuit node.Circuit
|
var circuit node.Circuit
|
||||||
for i := range 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
|
var hdr, pld [5]*prv.Key
|
||||||
for i := range hdr {
|
for i := range hdr {
|
||||||
hdr[i], pld[i] = sess[i].Header, sess[i].Payload
|
hdr[i], pld[i] = sess[i].Header, sess[i].Payload
|
||||||
}
|
}
|
||||||
cnf := nonce.NewID()
|
|
||||||
sk := wire.SendKeys(cnf, hdr, pld, clients[0].Node,
|
sk := wire.SendKeys(cnf, hdr, pld, clients[0].Node,
|
||||||
circuit, clients[0].KeySet)
|
circuit, clients[0].KeySet)
|
||||||
clients[0].RegisterConfirmation(func(cf nonce.ID) {
|
clients[0].RegisterConfirmation(func(cf nonce.ID) {
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ import (
|
|||||||
|
|
||||||
const nTotal = 6
|
const nTotal = 6
|
||||||
|
|
||||||
func CreateMockCircuitClients() (clients []*Client, e error) {
|
func CreateMockCircuitClients(inclSessions bool) (clients []*Client,
|
||||||
|
e error) {
|
||||||
|
|
||||||
clients = make([]*Client, nTotal)
|
clients = make([]*Client, nTotal)
|
||||||
nodes := make([]*node.Node, nTotal)
|
nodes := make([]*node.Node, nTotal)
|
||||||
transports := make([]ifc.Transport, nTotal)
|
transports := make([]ifc.Transport, nTotal)
|
||||||
@@ -36,21 +38,23 @@ func CreateMockCircuitClients() (clients []*Client, e error) {
|
|||||||
}
|
}
|
||||||
clients[i].AddrPort = nodes[i].AddrPort
|
clients[i].AddrPort = nodes[i].AddrPort
|
||||||
clients[i].Node = nodes[i]
|
clients[i].Node = nodes[i]
|
||||||
// create a session for all but the first
|
if inclSessions {
|
||||||
if i > 0 {
|
// create a session for all but the first
|
||||||
sessions[i-1] = node.NewSession(nonce.NewID(), nodes[i], math.MaxUint64, nil, nil)
|
if i > 0 {
|
||||||
// Add session to node, so it will be able to relay if
|
sessions[i-1] = node.NewSession(nonce.NewID(), nodes[i], math.MaxUint64, nil, nil)
|
||||||
// it gets a message with the key.
|
// Add session to node, so it will be able to relay if
|
||||||
nodes[i].Sessions = append(nodes[i].Sessions,
|
// it gets a message with the key.
|
||||||
sessions[i-1])
|
nodes[i].Sessions = append(nodes[i].Sessions,
|
||||||
nodes[0].Sessions = append(nodes[0].Sessions,
|
sessions[i-1])
|
||||||
sessions[i-1])
|
nodes[0].Sessions = append(nodes[0].Sessions,
|
||||||
// Normally only the client would have this in its
|
sessions[i-1])
|
||||||
// nodes, but we are sharing them for simple circuit
|
// Normally only the client would have this in its
|
||||||
// tests. Relays don't use this field, though clients
|
// nodes, but we are sharing them for simple circuit
|
||||||
// can be relays.
|
// tests. Relays don't use this field, though clients
|
||||||
nodes[i].Circuit = &node.Circuit{}
|
// can be relays.
|
||||||
nodes[i].Circuit[i-1] = sessions[i-1]
|
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
|
// Add each node to each other's Nodes except itself, this enables them
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ var (
|
|||||||
// GitRef is the gitref, as in refs/heads/branchname.
|
// GitRef is the gitref, as in refs/heads/branchname.
|
||||||
GitRef = "refs/heads/protocol"
|
GitRef = "refs/heads/protocol"
|
||||||
// ParentGitCommit is the commit hash of the parent HEAD.
|
// ParentGitCommit is the commit hash of the parent HEAD.
|
||||||
ParentGitCommit = "085c068d47046ba31c911c7ca226be6fcf32634b"
|
ParentGitCommit = "4b314c607788a95aa35d75fc0966816752a51579"
|
||||||
// BuildTime stores the time when the current binary was built.
|
// 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 lists the (latest) git tag on the release.
|
||||||
SemVer = "v0.1.7"
|
SemVer = "v0.1.7"
|
||||||
// PathBase is the path base returned from runtime caller.
|
// PathBase is the path base returned from runtime caller.
|
||||||
|
|||||||
Reference in New Issue
Block a user