diff --git a/network/manager.go b/network/manager.go index d685d448cce7f2cfddd3d000d34fe7deea3f1626..d023e12f000a9cdde59f0f22beba4de3a42fe0ce 100644 --- a/network/manager.go +++ b/network/manager.go @@ -15,10 +15,9 @@ import ( "gitlab.com/elixxir/client/context/stoppable" "gitlab.com/elixxir/client/network/health" "gitlab.com/elixxir/comms/client" - "gitlab.com/elixxir/primitives/format" - "gitlab.com/elixxir/primitives/switchboard" + "gitlab.com/elixxir/comms/network" "gitlab.com/xx_network/primitives/id" - "sync" + "gitlab.com/xx_network/primitives/ndf" "time" ) @@ -37,21 +36,35 @@ type Manager struct { //contains the health tracker which keeps track of if from the client's //perspective, the network is in good condition health *health.Tracker + + //contains the network instance + instance *network.Instance } // NewManager builds a new reception manager object using inputted key fields func NewManager(ctx *context.Context, uid *id.ID, privKey, pubKey, - salt []byte) (*Manager, error) { + salt []byte, partial *ndf.NetworkDefinition) (*Manager, error) { + + //start comms comms, err := client.NewClientComms(uid, pubKey, privKey, salt) if err != nil { - return nil, err + return nil, errors.WithMessage(err, "failed to create"+ + " client network manager") + } + + //start network instance + instance, err := network.NewInstance(comms.ProtoComms, partial, nil, nil) + if err != nil { + return nil, errors.WithMessage(err, "failed to create"+ + " client network manager") } cm := &Manager{ - Comms: comms, - Context: ctx, - runners: stoppable.NewMulti("network.Manager"), - health: health.Init(ctx, 5*time.Second), + Comms: comms, + Context: ctx, + runners: stoppable.NewMulti("network.Manager"), + health: health.Init(ctx, 5*time.Second), + instance: instance, } return cm, nil @@ -98,4 +111,8 @@ func (m *Manager) StopRunners(timeout time.Duration) error { func (m *Manager) GetHealthTracker() context.HealthTracker { return m.health +} + +func (m *Manager) GetInstance() *network.Instance { + return m.instance } \ No newline at end of file diff --git a/network/send.go b/network/send.go index 17a22048f709277bd8c3689244821eb5ef79b880..124112218b04f110d3ce3c45040ed91bef8a8452 100644 --- a/network/send.go +++ b/network/send.go @@ -7,6 +7,7 @@ package network import ( + "github.com/pkg/errors" "gitlab.com/elixxir/client/context/message" "gitlab.com/elixxir/client/context/params" "gitlab.com/elixxir/client/context/stoppable" @@ -18,8 +19,15 @@ import ( // SendE2E sends an end-to-end payload to the provided recipient with // the provided msgType. Returns the list of rounds in which parts of // the message were sent or an error if it fails. -func (m *Manager) SendE2E(m message.Send, e2eP params.E2E, cmixP params.CMIX) ( +func (m *Manager) SendE2E(msg message.Send, e2eP params.E2E, cmixP params.CMIX) ( []id.Round, error) { + + if !m.health.IsRunning() { + return nil, errors.New("Cannot send e2e message when the " + + "network is not healthy") + } + + return nil, nil } @@ -36,6 +44,21 @@ func (m *Manager) SendUnsafe(m message.Send) ([]id.Round, error) { // recipient. Note that both SendE2E and SendUnsafe call SendCMIX. // Returns the round ID of the round the payload was sent or an error // if it fails. -func (m *Manager) SendCMIX(message format.Message) (id.Round, error) { - return nil, nil +func (m *Manager) SendCMIX(msg format.Message) (id.Round, error) { + if !m.health.IsRunning() { + return 0, errors.New("Cannot send cmix message when the " + + "network is not healthy") + } + + return m.sendCMIX(msg) } + +// Internal send e2e which bypasses the network check, for use in SendE2E and +// SendUnsafe which do their own network checks +func (m *Manager) sendCMIX(message format.Message) (id.Round, error) { + + //get the round to send on + m. + + return 0, nil +} \ No newline at end of file