Skip to content
Snippets Groups Projects
Commit a50730d2 authored by Jake Taylor's avatar Jake Taylor
Browse files

remove networkManager from dummy messages

parent d01af01c
No related branches found
No related tags found
2 merge requests!510Release,!329Hotfix/dummy message bindings
......@@ -12,7 +12,6 @@ package dummy
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/xxdk"
......@@ -57,26 +56,23 @@ type Manager struct {
statusChan chan bool
// Cmix interfaces
net *xxdk.Cmix
store *storage.Session
networkManager interfaces.NetworkManager
rng *fastRNG.StreamGenerator
net *xxdk.Cmix
store *storage.Session
rng *fastRNG.StreamGenerator
}
// NewManager creates a new dummy Manager with the specified average send delta
// and the range used for generating random durations.
func NewManager(maxNumMessages int, avgSendDelta, randomRange time.Duration,
net *xxdk.Cmix, manager interfaces.NetworkManager) *Manager {
func NewManager(maxNumMessages int, avgSendDelta, randomRange time.Duration, net *xxdk.Cmix) *Manager {
clientStorage := net.GetStorage()
return newManager(maxNumMessages, avgSendDelta, randomRange, net,
&clientStorage, manager, net.GetRng())
&clientStorage, net.GetRng())
}
// newManager builds a new dummy Manager from fields explicitly passed in. This
// function is a helper function for NewManager to make it easier to test.
func newManager(maxNumMessages int, avgSendDelta, randomRange time.Duration,
net *xxdk.Cmix, store *storage.Session, networkManager interfaces.NetworkManager,
rng *fastRNG.StreamGenerator) *Manager {
net *xxdk.Cmix, store *storage.Session, rng *fastRNG.StreamGenerator) *Manager {
return &Manager{
maxNumMessages: maxNumMessages,
avgSendDelta: avgSendDelta,
......@@ -85,7 +81,6 @@ func newManager(maxNumMessages int, avgSendDelta, randomRange time.Duration,
statusChan: make(chan bool, statusChanLen),
net: net,
store: store,
networkManager: networkManager,
rng: rng,
}
}
......
......@@ -8,6 +8,7 @@
package dummy
import (
"gitlab.com/elixxir/client/cmix/message"
"sync"
"sync/atomic"
"time"
......@@ -32,7 +33,7 @@ const (
// sendThread is a thread that sends the dummy messages at random intervals.
func (m *Manager) sendThread(stop *stoppable.Single) {
jww.DEBUG.Print("Starting dummy traffic sending thread.")
jww.INFO.Print("Starting dummy traffic sending thread.")
nextSendChan := make(<-chan time.Time)
nextSendChanPtr := &(nextSendChan)
......@@ -57,15 +58,16 @@ func (m *Manager) sendThread(stop *stoppable.Single) {
go func() {
// get list of random messages and recipients
rng := m.rng.GetStream()
defer rng.Close()
msgs, err := m.newRandomMessages(rng)
if err != nil {
jww.FATAL.Panicf("Failed to generate dummy messages: %+v", err)
jww.ERROR.Printf("Failed to generate dummy messages: %+v", err)
return
}
rng.Close()
err = m.sendMessages(msgs)
err = m.sendMessages(msgs, rng)
if err != nil {
jww.FATAL.Panicf("Failed to send dummy messages: %+v", err)
jww.ERROR.Printf("Failed to send dummy messages: %+v", err)
}
}()
......@@ -84,7 +86,7 @@ func (m *Manager) stopSendThread(stop *stoppable.Single) {
}
// sendMessages generates and sends random messages.
func (m *Manager) sendMessages(msgs map[id.ID]format.Message) error {
func (m *Manager) sendMessages(msgs map[id.ID]format.Message, rng csprng.Source) error {
var sent, i int64
var wg sync.WaitGroup
......@@ -95,18 +97,12 @@ func (m *Manager) sendMessages(msgs map[id.ID]format.Message) error {
defer wg.Done()
// Fill the preimage with random data to ensure it is not repeatable
p := cmix.GetDefaultParams()
// FIXME: these fields no longer available
// through these params objects
// p.IdentityPreimage = make([]byte, 32)
// rng := m.rng.GetStream()
// if _, err := rng.Read(p.IdentityPreimage); err != nil {
// jww.FATAL.Panicf("Failed to generate data for random identity "+
// "preimage in e2e send: %+v", err)
// }
// rng.Close()
// p.DebugTag = "dummy"
_, _, err := m.networkManager.SendCMIX(msg, &recipient, p)
p := cmix.GetDefaultCMIXParams()
//Send(recipient *id.ID, fingerprint format.Fingerprint,
// service message.Service, payload, mac []byte, cmixParams CMIXParams) (
// id.Round, ephemeral.Id, error)
_, _, err := m.net.GetCmix().Send(&recipient, msg.GetKeyFP(),
message.GetRandomService(rng), msg.GetContents(), msg.GetMac(), p)
if err != nil {
jww.WARN.Printf("Failed to send dummy message %d/%d via "+
"Send: %+v", i, len(msgs), err)
......
......@@ -8,27 +8,11 @@
package dummy
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix/gateway"
"gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/client/event"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/ndf"
"io"
"math/rand"
"sync"
"testing"
"time"
)
......@@ -59,193 +43,8 @@ func newTestManager(maxNumMessages int, avgSendDelta, randomRange time.Duration,
randomRange: randomRange,
statusChan: make(chan bool, statusChanLen),
store: &store,
networkManager: newTestNetworkManager(sendErr, t),
rng: fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG),
}
return m
}
// ////////////////////////////////////////////////////////////////////////////////
// // Test Network State //
// ////////////////////////////////////////////////////////////////////////////////
// // testNetworkManager is a test implementation of NetworkManager interface.
type testNetworkManager struct {
instance *network.Instance
messages map[id.ID]format.Message
sendErr bool
sync.RWMutex
}
func newTestNetworkManager(sendErr bool, t *testing.T) interfaces.NetworkManager {
instanceComms := &connect.ProtoComms{
Manager: connect.NewManagerTesting(t),
}
thisInstance, err := network.NewInstanceTesting(instanceComms, getNDF(),
getNDF(), nil, nil, t)
if err != nil {
t.Fatalf("Failed to create new test instance: %v", err)
}
return &testNetworkManager{
instance: thisInstance,
messages: make(map[id.ID]format.Message),
sendErr: sendErr,
}
}
func (tnm *testNetworkManager) GetMsgListLen() int {
tnm.RLock()
defer tnm.RUnlock()
return len(tnm.messages)
}
func (tnm *testNetworkManager) GetMsgList() map[id.ID]format.Message {
tnm.RLock()
defer tnm.RUnlock()
return tnm.messages
}
func (tnm *testNetworkManager) GetMsg(recipient id.ID) format.Message {
tnm.RLock()
defer tnm.RUnlock()
return tnm.messages[recipient]
}
// TEST
func (tnm *testNetworkManager) SendE2E() (
[]id.Round, e2e.MessageID, time.Time, error) {
return nil, e2e.MessageID{}, time.Time{}, nil
}
// TEST
func (tnm *testNetworkManager) SendUnsafe() ([]id.Round, error) {
return []id.Round{}, nil
}
func (tnm *testNetworkManager) SendCMIX(message format.Message,
recipient *id.ID, _ cmix.Params) (id.Round, ephemeral.Id, error) {
tnm.Lock()
defer tnm.Unlock()
if tnm.sendErr {
return 0, ephemeral.Id{}, errors.New("Send error")
}
tnm.messages[*recipient] = message
return 0, ephemeral.Id{}, nil
}
func (tnm *testNetworkManager) SendManyCMIX([]cmix.TargetedCmixMessage, cmix.Params) (
id.Round, []ephemeral.Id, error) {
return 0, nil, nil
}
type dummyEventMgr struct{}
func (d *dummyEventMgr) Report(int, string, string, string) {}
func (tnm *testNetworkManager) GetEventManager() event.Reporter {
return &dummyEventMgr{}
}
func (tnm *testNetworkManager) GetInstance() *network.Instance { return tnm.instance }
func (tnm *testNetworkManager) GetAddressSpace() uint8 { return 0 }
func (tnm *testNetworkManager) GetHostParams() connect.HostParams { return connect.HostParams{} }
func (tnm *testNetworkManager) GetHealthTracker() interfaces.HealthTracker { return nil }
func (tnm *testNetworkManager) Follow(interfaces.ClientErrorReport) (stoppable.Stoppable, error) {
return nil, nil
}
func (tnm *testNetworkManager) CheckGarbledMessages() {}
func (tnm *testNetworkManager) CheckInProgressMessages() {}
func (tnm *testNetworkManager) InProgressRegistrations() int { return 0 }
func (tnm *testNetworkManager) GetSender() *gateway.Sender { return nil }
func (tnm *testNetworkManager) GetAddressSize() uint8 { return 0 }
func (tnm *testNetworkManager) RegisterAddressSizeNotification(string) (chan uint8, error) {
return nil, nil
}
func (tnm *testNetworkManager) UnregisterAddressSizeNotification(string) {}
func (tnm *testNetworkManager) SetPoolFilter(gateway.Filter) {}
func (tnm *testNetworkManager) GetVerboseRounds() string { return "" }
func (tnm *testNetworkManager) HasNode(*id.ID) bool { return false }
func (tnm *testNetworkManager) LookupHistoricalRound(id.Round, func(*mixmessages.RoundInfo, bool)) error {
return nil
}
func (tnm *testNetworkManager) NumRegisteredNodes() int { return 0 }
func (tnm *testNetworkManager) RegisterAddressSpaceNotification(string) (chan uint8, error) {
return nil, nil
}
func (tnm *testNetworkManager) SendToAny(func(*connect.Host) (interface{}, error), *stoppable.Single) (interface{}, error) {
return nil, nil
}
func (tnm *testNetworkManager) SendToPreferred([]*id.ID, func(*connect.Host, *id.ID, time.Duration) (interface{}, error), *stoppable.Single, time.Duration) (interface{}, error) {
return nil, nil
}
func (tnm *testNetworkManager) SetGatewayFilter(func(map[id.ID]int, *ndf.NetworkDefinition) map[id.ID]int) {
}
func (tnm *testNetworkManager) TrackServices(message.ServicesTracker) {}
func (tnm *testNetworkManager) TriggerNodeRegistration(*id.ID) {}
func (tnm *testNetworkManager) UnregisterAddressSpaceNotification(string) {}
func (tnm *testNetworkManager) AddFingerprint(*id.ID, format.Fingerprint, message.Processor) error {
return nil
}
func (tnm *testNetworkManager) DeleteFingerprint(*id.ID, format.Fingerprint) {}
func (tnm *testNetworkManager) DeleteClientFingerprints(*id.ID) {}
func (tnm *testNetworkManager) AddIdentity(*id.ID, time.Time, bool) error { return nil }
func (tnm *testNetworkManager) RemoveIdentity(*id.ID) {}
func (tnm *testNetworkManager) AddTrigger(*id.ID, message.Service, message.Processor) {}
func (tnm *testNetworkManager) DeleteTrigger(*id.ID, interfaces.Preimage, message.Processor) error {
return nil
}
func (tnm *testNetworkManager) DeleteClientTriggers(*id.ID) {}
// ////////////////////////////////////////////////////////////////////////////////
// // NDF Primes //
// ////////////////////////////////////////////////////////////////////////////////
func getNDF() *ndf.NetworkDefinition {
return &ndf.NetworkDefinition{
E2E: ndf.Group{
Prime: "E2EE983D031DC1DB6F1A7A67DF0E9A8E5561DB8E8D49413394C049B7A" +
"8ACCEDC298708F121951D9CF920EC5D146727AA4AE535B0922C688B55B3D" +
"D2AEDF6C01C94764DAB937935AA83BE36E67760713AB44A6337C20E78615" +
"75E745D31F8B9E9AD8412118C62A3E2E29DF46B0864D0C951C394A5CBBDC" +
"6ADC718DD2A3E041023DBB5AB23EBB4742DE9C1687B5B34FA48C3521632C" +
"4A530E8FFB1BC51DADDF453B0B2717C2BC6669ED76B4BDD5C9FF558E88F2" +
"6E5785302BEDBCA23EAC5ACE92096EE8A60642FB61E8F3D24990B8CB12EE" +
"448EEF78E184C7242DD161C7738F32BF29A841698978825B4111B4BC3E1E" +
"198455095958333D776D8B2BEEED3A1A1A221A6E37E664A64B83981C46FF" +
"DDC1A45E3D5211AAF8BFBC072768C4F50D7D7803D2D4F278DE8014A47323" +
"631D7E064DE81C0C6BFA43EF0E6998860F1390B5D3FEACAF1696015CB79C" +
"3F9C2D93D961120CD0E5F12CBB687EAB045241F96789C38E89D796138E63" +
"19BE62E35D87B1048CA28BE389B575E994DCA755471584A09EC723742DC3" +
"5873847AEF49F66E43873",
Generator: "2",
},
CMIX: ndf.Group{
Prime: "9DB6FB5951B66BB6FE1E140F1D2CE5502374161FD6538DF1648218642" +
"F0B5C48C8F7A41AADFA187324B87674FA1822B00F1ECF8136943D7C55757" +
"264E5A1A44FFE012E9936E00C1D3E9310B01C7D179805D3058B2A9F4BB6F" +
"9716BFE6117C6B5B3CC4D9BE341104AD4A80AD6C94E005F4B993E14F091E" +
"B51743BF33050C38DE235567E1B34C3D6A5C0CEAA1A0F368213C3D19843D" +
"0B4B09DCB9FC72D39C8DE41F1BF14D4BB4563CA28371621CAD3324B6A2D3" +
"92145BEBFAC748805236F5CA2FE92B871CD8F9C36D3292B5509CA8CAA77A" +
"2ADFC7BFD77DDA6F71125A7456FEA153E433256A2261C6A06ED3693797E7" +
"995FAD5AABBCFBE3EDA2741E375404AE25B",
Generator: "5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E2480" +
"9670716C613D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D" +
"1AA58C4328A06C46A15662E7EAA703A1DECF8BBB2D05DBE2EB956C142A33" +
"8661D10461C0D135472085057F3494309FFA73C611F78B32ADBB5740C361" +
"C9F35BE90997DB2014E2EF5AA61782F52ABEB8BD6432C4DD097BC5423B28" +
"5DAFB60DC364E8161F4A2A35ACA3A10B1C4D203CC76A470A33AFDCBDD929" +
"59859ABD8B56E1725252D78EAC66E71BA9AE3F1DD2487199874393CD4D83" +
"2186800654760E1E34C09E4D155179F9EC0DC4473F996BDCE6EED1CABED8" +
"B6F116F7AD9CF505DF0F998E34AB27514B0FFE7",
},
}
}
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package interfaces
import (
"time"
"gitlab.com/elixxir/comms/network"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/ndf"
"gitlab.com/elixxir/client/cmix"
"gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
)
type NetworkManager interface {
// Follow starts the tracking of the network in a new thread.
// Errors that occur are reported on the ClientErrorReport function if
// passed. The returned stopable can be used to stop the follower.
// Only one follower may run at a time.
Follow(report ClientErrorReport) (stoppable.Stoppable, error)
/*===Sending==========================================================*/
// SendCMIX sends a "raw" CMIX message payload to the provided
// recipient. Returns the round ID of the round the payload
// was sent or an error if it fails.
SendCMIX(message format.Message, recipient *id.ID, p cmix.Params) (
id.Round, ephemeral.Id, error)
// SendManyCMIX sends many "raw" cMix message payloads to each
// of the provided recipients. Used to send messages in group
// chats. Metadata is NOT as well protected with this call and
// can leak data about yourself. Should be replaced with
// multiple uses of SendCmix in most cases. Returns the round
// ID of the round the payload was sent or an error if it
// fails.
// WARNING: Potentially Unsafe
SendManyCMIX(messages []cmix.TargetedCmixMessage, p cmix.Params) (
id.Round, []ephemeral.Id, error)
/*===Message Reception================================================*/
/* Identities are all network identities which the client is currently
trying to pick up message on. An identity must be added
to receive messages, fake ones will be used to poll the network
if none are present. On creation of the network handler, the identity in
session storage will be automatically added*/
// AddIdentity adds an identity to be tracked
// If persistent is false, the identity will not be stored to disk and
// will be dropped on reload.
AddIdentity(id *id.ID, validUntil time.Time, persistent bool) error
// RemoveIdentity removes a currently tracked identity.
RemoveIdentity(id *id.ID)
/* Fingerprints are the primary mechanism of identifying a
picked up message over cMix. They are a unique one time use
255 bit vector generally associated with a specific encryption
key, but can be used for an alternative protocol.When
registering a fingerprint, a MessageProcessor is registered to
handle the message.*/
// AddFingerprint - Adds a fingerprint which will be handled by a
// specific processor for messages received by the given identity
AddFingerprint(identity *id.ID, fingerprint format.Fingerprint,
mp message.Processor) error
// DeleteFingerprint deletes a single fingerprint associated
// with the given identity if it exists
DeleteFingerprint(identity *id.ID, fingerprint format.Fingerprint)
// DeleteClientFingerprints deletes al fingerprint associated
// with the given identity if it exists
DeleteClientFingerprints(identity *id.ID)
/* trigger - predefined hash based tags appended to all cMix messages
which, though trial hashing, are used to determine if a message applies
to this client
Triggers are used for 2 purposes - They can be processed by the
notifications system, or can be used to implement custom non fingerprint
processing of payloads. I.E. key negotiation, broadcast negotiation
A tag is appended to the message of the format tag =
H(H(messageContents), preimage) and trial hashing is used to
determine if a message adheres to a tag.
WARNING: If a preimage is known by an adversary, they can
determine which messages are for the client on reception
(which is normally hidden due to collision between ephemeral
IDs.
Due to the extra overhead of trial hashing, triggers are
processed after fingerprints. If a fingerprint match occurs
on the message, triggers will not be handled.
Triggers are address to the session. When starting a new
client, all triggers must be re-added before
StartNetworkFollower is called.
*/
// AddTrigger - Adds a trigger which can call a message
// handing function or be used for notifications. Multiple
// triggers can be registered for the same preimage.
// preimage - the preimage which is triggered on
// type - a descriptive string of the trigger. Generally
// used in notifications
// source - a byte buffer of related data. Generally used in
// notifications.
// Example: Sender ID
AddTrigger(identity *id.ID, newTrigger message.Service,
response message.Processor)
// DeleteTrigger - If only a single response is associated with the
// preimage, the entire preimage is removed. If there is more than one
// response, only the given response is removed if nil is passed in for
// response, all triggers for the preimage will be removed
DeleteTrigger(identity *id.ID, preimage Preimage,
response message.Processor) error
// DeleteClientTriggers - deletes all triggers assoseated with
// the given identity
DeleteClientTriggers(identity *id.ID)
// TrackServices - Registers a callback which will get called
// every time triggers change.
// It will receive the triggers list every time it is modified.
// Will only get callbacks while the Network Follower is running.
// Multiple trackTriggers can be registered
TrackServices(message.ServicesTracker)
/* In inProcess */
// it is possible to receive a message over cMix before the
// fingerprints or triggers are registered. As a result, when
// handling fails, messages are put in the inProcess que for a
// set number of retries.
// CheckInProgressMessages - retry processing all messages in check in
// progress messages. Call this after adding fingerprints or triggers
//while the follower is running.
CheckInProgressMessages()
/*===Nodes============================================================*/
/* Keys must be registed with nodes in order to send messages
throug them. this process is in general automatically handled
by the Network Manager*/
// HasNode can be used to determine if a keying relationship
// exists with a node.
HasNode(nid *id.ID) bool
// NumRegisteredNodes Returns the total number of nodes we have a keying
// relationship with
NumRegisteredNodes() int
// TriggerNodeRegistration triggers the generation of a keying
// relationship with a given node
TriggerNodeRegistration(nid *id.ID)
/*===Historical Rounds================================================*/
/* A complete set of round info is not kept on the client, and sometimes
the network will need to be queried to get round info. Historical rounds
is the system internal to the Network Manager to do this.
It can be used externally as well.*/
// LookupHistoricalRound - looks up the passed historical round on the
// network
LookupHistoricalRound(rid id.Round,
callback func(info *mixmessages.RoundInfo,
success bool)) error
/*===Sender===========================================================*/
/* The sender handles sending comms to the network. It tracks
connections to gateways and handles proxying to gateways for
targeted comms. It can be used externally to contact gateway
directly, bypassing the majority of the network package*/
// SendToAny can be used to send the comm to any gateway in the network.
SendToAny(sendFunc func(host *connect.Host) (interface{}, error),
stop *stoppable.Single) (interface{}, error)
// SendToPreferred sends to a specific gateway, doing so through another
// gateway as a proxy if not directly connected.
SendToPreferred(targets []*id.ID, sendFunc func(host *connect.Host,
target *id.ID, timeout time.Duration) (interface{}, error),
stop *stoppable.Single, timeout time.Duration) (interface{},
error)
// SetGatewayFilter sets a function which will be used to
// filter gateways before connecting.
SetGatewayFilter(f func(map[id.ID]int,
*ndf.NetworkDefinition) map[id.ID]int)
// GetHostParams - returns the host params used when
// connectign to gateways
GetHostParams() connect.HostParams
/*===Address Space====================================================*/
// The network compasses identities into a smaller address
// space to cause collisions and hide the actual recipient of
// messages. These functions allow for the tracking of this
// addresses space. In general, address space issues are
// completely handled by the network package
// GetAddressSpace GetAddressSize returns the current address
// size of IDs. Blocks until an address size is known.
GetAddressSpace() uint8
// RegisterAddressSpaceNotification returns a channel that
// will trigger for every address space size update. The
// provided tag is the unique ID for the channel. Returns an
// error if the tag is already used.
RegisterAddressSpaceNotification(tag string) (chan uint8, error)
// UnregisterAddressSpaceNotification stops broadcasting
// address space size updates on the channel with the
// specified tag.
UnregisterAddressSpaceNotification(tag string)
/*===Accessors========================================================*/
// GetInstance returns the network instance object, which tracks the
// state of the network
GetInstance() *network.Instance
// GetHealthTracker returns the health tracker, which using a polling or
// event api lets you determine if network following is functioning
GetHealthTracker() HealthTracker
// GetVerboseRounds returns stringification of verbose round info
GetVerboseRounds() string
}
type Preimage [32]byte
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment