Skip to content
Snippets Groups Projects
Commit a753a5b6 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

added the network instance

parent 6b4afd32
No related branches found
No related tags found
No related merge requests found
......@@ -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,14 +36,27 @@ 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{
......@@ -52,6 +64,7 @@ func NewManager(ctx *context.Context, uid *id.ID, privKey, pubKey,
Context: ctx,
runners: stoppable.NewMulti("network.Manager"),
health: health.Init(ctx, 5*time.Second),
instance: instance,
}
return cm, nil
......@@ -99,3 +112,7 @@ 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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment