Skip to content
Snippets Groups Projects
Commit 8b4c4243 authored by Jono Wenger's avatar Jono Wenger
Browse files

Merge branches 'xx-3003/update-id-creation' and 'agile/EphemeralReception' of...

Merge branches 'xx-3003/update-id-creation' and 'agile/EphemeralReception' of gitlab.com:elixxir/client into xx-3003/update-id-creation

 Conflicts:
	bindings/send.go
parents bcca64f7 24dc0141
No related branches found
No related tags found
No related merge requests found
Showing
with 376 additions and 42 deletions
...@@ -40,6 +40,8 @@ type Client struct { ...@@ -40,6 +40,8 @@ type Client struct {
switchboard *switchboard.Switchboard switchboard *switchboard.Switchboard
//object used for communications //object used for communications
comms *client.Comms comms *client.Comms
// Network parameters
parameters params.Network
// note that the manager has a pointer to the context in many cases, but // note that the manager has a pointer to the context in many cases, but
// this interface allows it to be mocked for easy testing without the // this interface allows it to be mocked for easy testing without the
...@@ -146,7 +148,7 @@ func NewPrecannedClient(precannedID uint, defJSON, storageDir string, password [ ...@@ -146,7 +148,7 @@ func NewPrecannedClient(precannedID uint, defJSON, storageDir string, password [
} }
// OpenClient session, but don't connect to the network or log in // OpenClient session, but don't connect to the network or log in
func OpenClient(storageDir string, password []byte) (*Client, error) { func OpenClient(storageDir string, password []byte, parameters params.Network) (*Client, error) {
jww.INFO.Printf("OpenClient()") jww.INFO.Printf("OpenClient()")
// Use fastRNG for RNG ops (AES fortuna based RNG using system RNG) // Use fastRNG for RNG ops (AES fortuna based RNG using system RNG)
rngStreamGen := fastRNG.NewStreamGenerator(12, 3, rngStreamGen := fastRNG.NewStreamGenerator(12, 3,
...@@ -168,16 +170,17 @@ func OpenClient(storageDir string, password []byte) (*Client, error) { ...@@ -168,16 +170,17 @@ func OpenClient(storageDir string, password []byte) (*Client, error) {
network: nil, network: nil,
runner: stoppable.NewMulti("client"), runner: stoppable.NewMulti("client"),
status: newStatusTracker(), status: newStatusTracker(),
parameters: parameters,
} }
return c, nil return c, nil
} }
// Login initalizes a client object from existing storage. // Login initalizes a client object from existing storage.
func Login(storageDir string, password []byte) (*Client, error) { func Login(storageDir string, password []byte, parameters params.Network) (*Client, error) {
jww.INFO.Printf("Login()") jww.INFO.Printf("Login()")
c, err := OpenClient(storageDir, password) c, err := OpenClient(storageDir, password, parameters)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -187,8 +190,8 @@ func Login(storageDir string, password []byte) (*Client, error) { ...@@ -187,8 +190,8 @@ func Login(storageDir string, password []byte) (*Client, error) {
c.services = newServiceProcessiesList(c.runner) c.services = newServiceProcessiesList(c.runner)
//get the user from session //get the user from session
user := c.storage.User() u := c.storage.User()
cryptoUser := user.GetCryptographicIdentity() cryptoUser := u.GetCryptographicIdentity()
//start comms //start comms
c.comms, err = client.NewClientComms(cryptoUser.GetTransmissionID(), c.comms, err = client.NewClientComms(cryptoUser.GetTransmissionID(),
...@@ -228,7 +231,7 @@ func Login(storageDir string, password []byte) (*Client, error) { ...@@ -228,7 +231,7 @@ func Login(storageDir string, password []byte) (*Client, error) {
// Initialize network and link it to context // Initialize network and link it to context
c.network, err = network.NewManager(c.storage, c.switchboard, c.rng, c.comms, c.network, err = network.NewManager(c.storage, c.switchboard, c.rng, c.comms,
params.GetDefaultNetwork(), def) parameters, def)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -293,7 +296,7 @@ func (c *Client) StartNetworkFollower() error { ...@@ -293,7 +296,7 @@ func (c *Client) StartNetworkFollower() error {
} }
c.runner.Add(stopFollow) c.runner.Add(stopFollow)
// Key exchange // Key exchange
c.runner.Add(keyExchange.Start(c.switchboard, c.storage, c.network, params.GetDefaultRekey())) c.runner.Add(keyExchange.Start(c.switchboard, c.storage, c.network, c.parameters.Rekey))
err = c.status.toRunning() err = c.status.toRunning()
if err != nil { if err != nil {
...@@ -353,6 +356,7 @@ func (c *Client) GetSwitchboard() interfaces.Switchboard { ...@@ -353,6 +356,7 @@ func (c *Client) GetSwitchboard() interfaces.Switchboard {
// events. // events.
func (c *Client) GetRoundEvents() interfaces.RoundEvents { func (c *Client) GetRoundEvents() interfaces.RoundEvents {
jww.INFO.Printf("GetRoundEvents()") jww.INFO.Printf("GetRoundEvents()")
jww.WARN.Printf("GetRoundEvents does not handle Client Errors edge case!")
return c.network.GetInstance().GetRoundEvents() return c.network.GetInstance().GetRoundEvents()
} }
......
...@@ -47,7 +47,7 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader, ...@@ -47,7 +47,7 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader,
} }
// check that the request is being sent from the proper ID // check that the request is being sent from the proper ID
if !me.ID.Cmp(storage.GetUser().TransmissionID) { if !me.ID.Cmp(storage.GetUser().ReceptionID) {
return errors.Errorf("Authenticated channel request " + return errors.Errorf("Authenticated channel request " +
"can only be sent from user's identity") "can only be sent from user's identity")
} }
...@@ -116,7 +116,7 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader, ...@@ -116,7 +116,7 @@ func RequestAuth(partner, me contact.Contact, message string, rng io.Reader,
jww.INFO.Printf("RequestAuth THEIRPUBKEY: %v", partner.DhPubKey.Bytes()) jww.INFO.Printf("RequestAuth THEIRPUBKEY: %v", partner.DhPubKey.Bytes())
/*encrypt payload*/ /*encrypt payload*/
requestFmt.SetID(storage.GetUser().TransmissionID) requestFmt.SetID(storage.GetUser().ReceptionID)
requestFmt.SetMsgPayload(msgPayloadBytes) requestFmt.SetMsgPayload(msgPayloadBytes)
ecrFmt.SetOwnership(ownership) ecrFmt.SetOwnership(ownership)
ecrPayload, mac := cAuth.Encrypt(newPrivKey, partner.DhPubKey, ecrPayload, mac := cAuth.Encrypt(newPrivKey, partner.DhPubKey,
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/interfaces/contact" "gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/interfaces/params"
"gitlab.com/elixxir/client/interfaces/utility" "gitlab.com/elixxir/client/interfaces/utility"
"gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/mixmessages"
ds "gitlab.com/elixxir/comms/network/dataStructures" ds "gitlab.com/elixxir/comms/network/dataStructures"
...@@ -75,8 +76,13 @@ func NewPrecannedClient(precannedID int, network, storageDir string, password [] ...@@ -75,8 +76,13 @@ func NewPrecannedClient(precannedID int, network, storageDir string, password []
// memory and stored as securely as possible using the memguard library. // memory and stored as securely as possible using the memguard library.
// Login does not block on network connection, and instead loads and // Login does not block on network connection, and instead loads and
// starts subprocesses to perform network operations. // starts subprocesses to perform network operations.
func Login(storageDir string, password []byte) (*Client, error) { func Login(storageDir string, password []byte, parameters string) (*Client, error) {
client, err := api.Login(storageDir, password) p, err := params.GetNetworkParameters(parameters)
if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to login: %+v", err))
}
client, err := api.Login(storageDir, password, p)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to login: %+v", err)) return nil, errors.New(fmt.Sprintf("Failed to login: %+v", err))
} }
...@@ -291,15 +297,15 @@ func (c *Client) RegisterRoundEventsHandler(rid int, cb RoundEventCallback, ...@@ -291,15 +297,15 @@ func (c *Client) RegisterRoundEventsHandler(rid int, cb RoundEventCallback,
} }
// RegisterMessageDeliveryCB allows the caller to get notified if the rounds a // RegisterMessageDeliveryCB allows the caller to get notified if the rounds a
// message was sent in sucesfully completed. Under the hood, this uses the same // message was sent in successfully completed. Under the hood, this uses the same
// interface as RegisterRoundEventsHandler, but provides a convienet way to use // interface as RegisterRoundEventsHandler, but provides a convent way to use
// the interface in its most common form, looking up the result of message // the interface in its most common form, looking up the result of message
// retreval // retrieval
// //
// The callbacks will return at timeoutMS if no state update occurs // The callbacks will return at timeoutMS if no state update occurs
// //
// This function takes the marshaled send report to ensure a memory leak does // This function takes the marshaled send report to ensure a memory leak does
// not occur as a result of both sides of the bindings holding a refrence to // not occur as a result of both sides of the bindings holding a reference to
// the same pointer. // the same pointer.
func (c *Client) RegisterMessageDeliveryCB(marshaledSendReport []byte, func (c *Client) RegisterMessageDeliveryCB(marshaledSendReport []byte,
mdc MessageDeliveryCallback, timeoutMS int) (*Unregister, error) { mdc MessageDeliveryCallback, timeoutMS int) (*Unregister, error) {
......
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC // // Copyright © 2021 xx network SEZC //
// // // //
// Use of this source code is governed by a license that can be found in the // // Use of this source code is governed by a license that can be found in the //
// LICENSE file // // LICENSE file //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
package params // Contains params-related bindings
//import ( package bindings
// "time"
//)
type NodeKeys struct { import (
WorkerPoolSize uint "gitlab.com/elixxir/client/interfaces/params"
)
func (c *Client) GetCMIXParams() (string, error) {
p, err := params.GetDefaultCMIX().Marshal()
return string(p), err
}
func (c *Client) GetE2EParams() (string, error) {
p, err := params.GetDefaultE2E().Marshal()
return string(p), err
} }
func GetDefaultNodeKeys() NodeKeys { func (c *Client) GetNetworkParams() (string, error) {
return NodeKeys{ p, err := params.GetDefaultNetwork().Marshal()
WorkerPoolSize: 10, return string(p), err
} }
func (c *Client) GetUnsafeParams() (string, error) {
p, err := params.GetDefaultUnsafe().Marshal()
return string(p), err
} }
...@@ -30,8 +30,13 @@ import ( ...@@ -30,8 +30,13 @@ import (
// This will return the round the message was sent on if it is successfully sent // This will return the round the message was sent on if it is successfully sent
// This can be used to register a round event to learn about message delivery. // This can be used to register a round event to learn about message delivery.
// on failure a round id of -1 is returned // on failure a round id of -1 is returned
// todo- return the ephemeral ID func (c *Client) SendCmix(recipient, contents []byte, parameters string) (int, error) {
func (c *Client) SendCmix(recipient, contents []byte) (int, error) { p, err := params.GetCMIXParameters(parameters)
if err != nil {
return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v",
err))
}
u, err := id.Unmarshal(recipient) u, err := id.Unmarshal(recipient)
if err != nil { if err != nil {
return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v", return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v",
...@@ -44,7 +49,7 @@ func (c *Client) SendCmix(recipient, contents []byte) (int, error) { ...@@ -44,7 +49,7 @@ func (c *Client) SendCmix(recipient, contents []byte) (int, error) {
err)) err))
} }
rid, _, err := c.api.SendCMIX(msg, u, params.GetDefaultCMIX()) rid, _, err := c.api.SendCMIX(msg, u, p)
if err != nil { if err != nil {
return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v", return -1, errors.New(fmt.Sprintf("Failed to sendCmix: %+v",
err)) err))
...@@ -61,7 +66,12 @@ func (c *Client) SendCmix(recipient, contents []byte) (int, error) { ...@@ -61,7 +66,12 @@ func (c *Client) SendCmix(recipient, contents []byte) (int, error) {
// Message Types can be found in client/interfaces/message/type.go // Message Types can be found in client/interfaces/message/type.go
// Make sure to not conflict with ANY default message types with custom types // Make sure to not conflict with ANY default message types with custom types
func (c *Client) SendUnsafe(recipient, payload []byte, func (c *Client) SendUnsafe(recipient, payload []byte,
messageType int) (*RoundList, error) { messageType int, parameters string) (*RoundList, error) {
p, err := params.GetUnsafeParameters(parameters)
if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to sendUnsafe: %+v",
err))
}
u, err := id.Unmarshal(recipient) u, err := id.Unmarshal(recipient)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to sendUnsafe: %+v", return nil, errors.New(fmt.Sprintf("Failed to sendUnsafe: %+v",
...@@ -74,7 +84,7 @@ func (c *Client) SendUnsafe(recipient, payload []byte, ...@@ -74,7 +84,7 @@ func (c *Client) SendUnsafe(recipient, payload []byte,
MessageType: message.Type(messageType), MessageType: message.Type(messageType),
} }
rids, err := c.api.SendUnsafe(m, params.GetDefaultUnsafe()) rids, err := c.api.SendUnsafe(m, p)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to sendUnsafe: %+v", return nil, errors.New(fmt.Sprintf("Failed to sendUnsafe: %+v",
err)) err))
...@@ -89,7 +99,12 @@ func (c *Client) SendUnsafe(recipient, payload []byte, ...@@ -89,7 +99,12 @@ func (c *Client) SendUnsafe(recipient, payload []byte,
// //
// Message Types can be found in client/interfaces/message/type.go // Message Types can be found in client/interfaces/message/type.go
// Make sure to not conflict with ANY default message types // Make sure to not conflict with ANY default message types
func (c *Client) SendE2E(recipient, payload []byte, messageType int) (*SendReport, error) { func (c *Client) SendE2E(recipient, payload []byte, messageType int, parameters string) (*SendReport, error) {
p, err := params.GetE2EParameters(parameters)
if err != nil {
return nil, errors.New(fmt.Sprintf("Failed SendE2E: %+v", err))
}
u, err := id.Unmarshal(recipient) u, err := id.Unmarshal(recipient)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Failed SendE2E: %+v", err)) return nil, errors.New(fmt.Sprintf("Failed SendE2E: %+v", err))
...@@ -101,7 +116,7 @@ func (c *Client) SendE2E(recipient, payload []byte, messageType int) (*SendRepor ...@@ -101,7 +116,7 @@ func (c *Client) SendE2E(recipient, payload []byte, messageType int) (*SendRepor
MessageType: message.Type(messageType), MessageType: message.Type(messageType),
} }
rids, mid, err := c.api.SendE2E(m, params.GetDefaultE2E()) rids, mid, err := c.api.SendE2E(m, p)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Failed SendE2E: %+v", err)) return nil, errors.New(fmt.Sprintf("Failed SendE2E: %+v", err))
} }
......
...@@ -22,9 +22,9 @@ var initCmd = &cobra.Command{ ...@@ -22,9 +22,9 @@ var initCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
client := createClient() client := createClient()
user := client.GetUser() user := client.GetUser()
jww.INFO.Printf("User: %s", user.TransmissionID) jww.INFO.Printf("User: %s", user.ReceptionID)
writeContact(user.GetContact()) writeContact(user.GetContact())
fmt.Printf("%s\n", user.TransmissionID) fmt.Printf("%s\n", user.ReceptionID)
}, },
} }
......
...@@ -49,7 +49,7 @@ var rootCmd = &cobra.Command{ ...@@ -49,7 +49,7 @@ var rootCmd = &cobra.Command{
client := initClient() client := initClient()
user := client.GetUser() user := client.GetUser()
jww.INFO.Printf("User: %s", user.TransmissionID) jww.INFO.Printf("User: %s", user.ReceptionID)
writeContact(user.GetContact()) writeContact(user.GetContact())
// Set up reception handler // Set up reception handler
...@@ -212,7 +212,7 @@ func createClient() *api.Client { ...@@ -212,7 +212,7 @@ func createClient() *api.Client {
} }
} }
client, err := api.OpenClient(storeDir, []byte(pass)) client, err := api.OpenClient(storeDir, []byte(pass), params.GetDefaultNetwork())
if err != nil { if err != nil {
jww.FATAL.Panicf("%+v", err) jww.FATAL.Panicf("%+v", err)
} }
...@@ -226,7 +226,7 @@ func initClient() *api.Client { ...@@ -226,7 +226,7 @@ func initClient() *api.Client {
storeDir := viper.GetString("session") storeDir := viper.GetString("session")
//load the client //load the client
client, err := api.Login(storeDir, []byte(pass)) client, err := api.Login(storeDir, []byte(pass), params.GetDefaultNetwork())
if err != nil { if err != nil {
jww.FATAL.Panicf("%+v", err) jww.FATAL.Panicf("%+v", err)
} }
......
...@@ -34,7 +34,7 @@ var udCmd = &cobra.Command{ ...@@ -34,7 +34,7 @@ var udCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
client := initClient() client := initClient()
user := client.GetUser() user := client.GetUser()
jww.INFO.Printf("User: %s", user.TransmissionID) jww.INFO.Printf("User: %s", user.ReceptionID)
writeContact(user.GetContact()) writeContact(user.GetContact())
// Set up reception handler // Set up reception handler
......
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
package params package params
import "time" import (
"encoding/json"
"time"
)
type CMIX struct { type CMIX struct {
//maximum number of rounds to try and send on //maximum number of rounds to try and send on
...@@ -23,3 +26,19 @@ func GetDefaultCMIX() CMIX { ...@@ -23,3 +26,19 @@ func GetDefaultCMIX() CMIX {
RetryDelay: 1 * time.Second, RetryDelay: 1 * time.Second,
} }
} }
func (c CMIX) Marshal() ([]byte, error) {
return json.Marshal(c)
}
// Obtain default CMIX parameters, or override with given parameters if set
func GetCMIXParameters(params string) (CMIX, error) {
p := GetDefaultCMIX()
if len(params) > 0 {
err := json.Unmarshal([]byte(params), &p)
if err != nil {
return CMIX{}, err
}
}
return p, nil
}
...@@ -18,3 +18,38 @@ func TestGetDefaultCMIX(t *testing.T) { ...@@ -18,3 +18,38 @@ func TestGetDefaultCMIX(t *testing.T) {
t.Errorf("GetDefaultCMIX did not return expected values") t.Errorf("GetDefaultCMIX did not return expected values")
} }
} }
// New params path
func TestGetCMIXParameters(t *testing.T) {
p := GetDefaultCMIX()
expected := p.RoundTries + 1
p.RoundTries = expected
jsonString, err := p.Marshal()
if err != nil {
t.Errorf("%+v", err)
}
q, err := GetCMIXParameters(string(jsonString))
if err != nil {
t.Errorf("%+v", err)
}
if q.RoundTries != expected {
t.Errorf("Parameters failed to change! Got %d, Expected %d", q.RoundTries, expected)
}
}
// No new params path
func TestGetCMIXParameters_Default(t *testing.T) {
p := GetDefaultCMIX()
q, err := GetCMIXParameters("")
if err != nil {
t.Errorf("%+v", err)
}
if q.RoundTries != p.RoundTries {
t.Errorf("Parameters failed to change! Got %d, Expected %d", q.RoundTries, p.RoundTries)
}
}
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
package params package params
import "fmt" import (
"encoding/json"
"fmt"
)
type E2E struct { type E2E struct {
Type SendType Type SendType
...@@ -19,6 +22,21 @@ func GetDefaultE2E() E2E { ...@@ -19,6 +22,21 @@ func GetDefaultE2E() E2E {
CMIX: GetDefaultCMIX(), CMIX: GetDefaultCMIX(),
} }
} }
func (e E2E) Marshal() ([]byte, error) {
return json.Marshal(e)
}
// Obtain default E2E parameters, or override with given parameters if set
func GetE2EParameters(params string) (E2E, error) {
p := GetDefaultE2E()
if len(params) > 0 {
err := json.Unmarshal([]byte(params), &p)
if err != nil {
return E2E{}, err
}
}
return p, nil
}
type SendType uint8 type SendType uint8
......
...@@ -31,3 +31,38 @@ func TestSendType_String(t *testing.T) { ...@@ -31,3 +31,38 @@ func TestSendType_String(t *testing.T) {
t.Errorf("Running String on unknown E2E type got %s", e.Type.String()) t.Errorf("Running String on unknown E2E type got %s", e.Type.String())
} }
} }
// New params path
func TestGetE2EParameters(t *testing.T) {
p := GetDefaultE2E()
expected := p.RoundTries + 1
p.RoundTries = expected
jsonString, err := p.Marshal()
if err != nil {
t.Errorf("%+v", err)
}
q, err := GetE2EParameters(string(jsonString))
if err != nil {
t.Errorf("%+v", err)
}
if q.RoundTries != expected {
t.Errorf("Parameters failed to change! Got %d, Expected %d", q.RoundTries, expected)
}
}
// No new params path
func TestGetE2EParameters_Default(t *testing.T) {
p := GetDefaultE2E()
q, err := GetE2EParameters("")
if err != nil {
t.Errorf("%+v", err)
}
if q.RoundTries != p.RoundTries {
t.Errorf("Parameters failed to change! Got %d, Expected %d", q.RoundTries, p.RoundTries)
}
}
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
package params package params
import "time" import (
"time"
)
type Rekey struct { type Rekey struct {
RoundTimeout time.Duration RoundTimeout time.Duration
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
package params package params
import "time" import (
"time"
)
type Messages struct { type Messages struct {
MessageReceptionBuffLen uint MessageReceptionBuffLen uint
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
package params package params
import ( import (
"encoding/json"
"time" "time"
) )
...@@ -23,6 +24,7 @@ type Network struct { ...@@ -23,6 +24,7 @@ type Network struct {
Rounds Rounds
Messages Messages
Rekey
} }
func GetDefaultNetwork() Network { func GetDefaultNetwork() Network {
...@@ -36,3 +38,19 @@ func GetDefaultNetwork() Network { ...@@ -36,3 +38,19 @@ func GetDefaultNetwork() Network {
n.Messages = GetDefaultMessage() n.Messages = GetDefaultMessage()
return n return n
} }
func (n Network) Marshal() ([]byte, error) {
return json.Marshal(n)
}
// Obtain default Network parameters, or override with given parameters if set
func GetNetworkParameters(params string) (Network, error) {
p := GetDefaultNetwork()
if len(params) > 0 {
err := json.Unmarshal([]byte(params), &p)
if err != nil {
return Network{}, err
}
}
return p, nil
}
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2021 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package params
import "testing"
// New params path
func TestGetNetworkParameters(t *testing.T) {
p := GetDefaultNetwork()
expected := p.MaxCheckedRounds + 1
p.MaxCheckedRounds = expected
jsonString, err := p.Marshal()
if err != nil {
t.Errorf("%+v", err)
}
q, err := GetNetworkParameters(string(jsonString))
if err != nil {
t.Errorf("%+v", err)
}
if q.MaxCheckedRounds != expected {
t.Errorf("Parameters failed to change! Got %d, Expected %d", q.MaxCheckedRounds, expected)
}
}
// No new params path
func TestGetNetworkParameters_Default(t *testing.T) {
p := GetDefaultNetwork()
q, err := GetNetworkParameters("")
if err != nil {
t.Errorf("%+v", err)
}
if q.MaxCheckedRounds != p.MaxCheckedRounds {
t.Errorf("Parameters failed to change! Got %d, Expected %d", q.MaxCheckedRounds, p.MaxCheckedRounds)
}
}
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
package params package params
import "time" import (
"time"
)
type Rounds struct { type Rounds struct {
// maximum number of times to attempt to retrieve a round from a gateway // maximum number of times to attempt to retrieve a round from a gateway
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
package params package params
import "encoding/json"
type Unsafe struct { type Unsafe struct {
CMIX CMIX
} }
...@@ -14,3 +16,19 @@ type Unsafe struct { ...@@ -14,3 +16,19 @@ type Unsafe struct {
func GetDefaultUnsafe() Unsafe { func GetDefaultUnsafe() Unsafe {
return Unsafe{CMIX: GetDefaultCMIX()} return Unsafe{CMIX: GetDefaultCMIX()}
} }
func (u Unsafe) Marshal() ([]byte, error) {
return json.Marshal(u)
}
// Obtain default Unsafe parameters, or override with given parameters if set
func GetUnsafeParameters(params string) (Unsafe, error) {
p := GetDefaultUnsafe()
if len(params) > 0 {
err := json.Unmarshal([]byte(params), &p)
if err != nil {
return Unsafe{}, err
}
}
return p, nil
}
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2021 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package params
import "testing"
// New params path
func TestGetUnsafeParameters(t *testing.T) {
p := GetDefaultUnsafe()
expected := p.RoundTries + 1
p.RoundTries = expected
jsonString, err := p.Marshal()
if err != nil {
t.Errorf("%+v", err)
}
q, err := GetUnsafeParameters(string(jsonString))
if err != nil {
t.Errorf("%+v", err)
}
if q.RoundTries != expected {
t.Errorf("Parameters failed to change! Got %d, Expected %d", q.RoundTries, expected)
}
}
// No new params path
func TestGetUnsafeParameters_Default(t *testing.T) {
p := GetDefaultUnsafe()
q, err := GetUnsafeParameters("")
if err != nil {
t.Errorf("%+v", err)
}
if q.RoundTries != p.RoundTries {
t.Errorf("Parameters failed to change! Got %d, Expected %d", q.RoundTries, p.RoundTries)
}
}
...@@ -23,12 +23,13 @@ package network ...@@ -23,12 +23,13 @@ package network
// instance // instance
import ( import (
"gitlab.com/elixxir/client/network/gateway" "bytes"
//"gitlab.com/elixxir/client/storage"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
bloom "gitlab.com/elixxir/bloomfilter" bloom "gitlab.com/elixxir/bloomfilter"
"gitlab.com/elixxir/client/network/gateway"
pb "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/primitives/knownRounds" "gitlab.com/elixxir/primitives/knownRounds"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
...@@ -62,7 +63,7 @@ func (m *manager) followNetwork(quitCh <-chan struct{}) { ...@@ -62,7 +63,7 @@ func (m *manager) followNetwork(quitCh <-chan struct{}) {
} }
} }
var followCnt int = 0 var followCnt = 0
// executes each iteration of the follower // executes each iteration of the follower
func (m *manager) follow(rng csprng.Source, comms followNetworkComms) { func (m *manager) follow(rng csprng.Source, comms followNetworkComms) {
...@@ -86,10 +87,10 @@ func (m *manager) follow(rng csprng.Source, comms followNetworkComms) { ...@@ -86,10 +87,10 @@ func (m *manager) follow(rng csprng.Source, comms followNetworkComms) {
LastUpdate: uint64(m.Instance.GetLastUpdateID()), LastUpdate: uint64(m.Instance.GetLastUpdateID()),
ClientID: m.Uid.Bytes(), ClientID: m.Uid.Bytes(),
} }
jww.TRACE.Printf("polling %s for NDF", gwHost) jww.TRACE.Printf("Polling %s for NDF...", gwHost)
pollResp, err := comms.SendPoll(gwHost, &pollReq) pollResp, err := comms.SendPoll(gwHost, &pollReq)
if err != nil { if err != nil {
jww.ERROR.Printf("%+v", err) jww.ERROR.Printf("Unable to poll %s for NDF: %+v", gwHost, err)
return return
} }
...@@ -98,7 +99,7 @@ func (m *manager) follow(rng csprng.Source, comms followNetworkComms) { ...@@ -98,7 +99,7 @@ func (m *manager) follow(rng csprng.Source, comms followNetworkComms) {
gwRoundsState := &knownRounds.KnownRounds{} gwRoundsState := &knownRounds.KnownRounds{}
err = gwRoundsState.Unmarshal(pollResp.KnownRounds) err = gwRoundsState.Unmarshal(pollResp.KnownRounds)
if err != nil { if err != nil {
jww.ERROR.Printf("Failed to unmartial: %+v", err) jww.ERROR.Printf("Failed to unmarshal: %+v", err)
return return
} }
var filterList []*bloom.Ring var filterList []*bloom.Ring
...@@ -127,13 +128,13 @@ func (m *manager) follow(rng csprng.Source, comms followNetworkComms) { ...@@ -127,13 +128,13 @@ func (m *manager) follow(rng csprng.Source, comms followNetworkComms) {
if pollResp.PartialNDF != nil { if pollResp.PartialNDF != nil {
err = m.Instance.UpdatePartialNdf(pollResp.PartialNDF) err = m.Instance.UpdatePartialNdf(pollResp.PartialNDF)
if err != nil { if err != nil {
jww.ERROR.Printf("%+v", err) jww.ERROR.Printf("Unable to update partial NDF: %+v", err)
return return
} }
err = m.Instance.UpdateGatewayConnections() err = m.Instance.UpdateGatewayConnections()
if err != nil { if err != nil {
jww.ERROR.Printf("%+v", err) jww.ERROR.Printf("Unable to update gateway connections: %+v", err)
return return
} }
} }
...@@ -142,11 +143,48 @@ func (m *manager) follow(rng csprng.Source, comms followNetworkComms) { ...@@ -142,11 +143,48 @@ func (m *manager) follow(rng csprng.Source, comms followNetworkComms) {
// network // network
if pollResp.Updates != nil { if pollResp.Updates != nil {
err = m.Instance.RoundUpdates(pollResp.Updates) err = m.Instance.RoundUpdates(pollResp.Updates)
//jww.TRACE.Printf("%+v", pollResp.Updates)
if err != nil { if err != nil {
jww.ERROR.Printf("%+v", err) jww.ERROR.Printf("%+v", err)
return return
} }
// Iterate over ClientErrors for each RoundUpdate
for _, update := range pollResp.Updates {
// Ignore irrelevant updates
if update.State != uint32(states.COMPLETED) && update.State != uint32(states.FAILED) {
continue
}
for _, clientErr := range update.ClientErrors {
// If this Client appears in the ClientError
if bytes.Equal(clientErr.ClientId, m.Session.GetUser().TransmissionID.Marshal()) {
// Obtain relevant NodeGateway information
nGw, err := m.Instance.GetNodeAndGateway(gwHost.GetId())
if err != nil {
jww.ERROR.Printf("Unable to get NodeGateway: %+v", err)
return
}
nid, err := nGw.Node.GetNodeId()
if err != nil {
jww.ERROR.Printf("Unable to get NodeID: %+v", err)
return
}
// FIXME: Should be able to trigger proper type of round event
// FIXME: without mutating the RoundInfo. Signature also needs verified
// FIXME: before keys are deleted
update.State = uint32(states.FAILED)
m.Instance.GetRoundEvents().TriggerRoundEvent(update)
// Delete all existing keys and trigger a re-registration with the relevant Node
m.Session.Cmix().Remove(nid)
m.Instance.GetAddGatewayChan() <- nGw
}
}
}
} }
// ---- Round Processing ----- // ---- Round Processing -----
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment