Skip to content
Snippets Groups Projects
Commit 18cac607 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Merge remote-tracking branch 'origin/peppa/newClient' into XX-2656/newload

parents 90de21ce 5e42cfd3
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ package context
import (
"gitlab.com/elixxir/client/context/message"
"gitlab.com/elixxir/client/context/params"
"gitlab.com/elixxir/client/context/stoppable"
"gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id"
......@@ -14,6 +15,9 @@ type NetworkManager interface {
SendCMIX(message format.Message, p params.CMIX) (id.Round, error)
GetInstance() *network.Instance
GetHealthTracker() HealthTracker
RegisterWithPermissioning(string) ([]byte, error)
GetRemoteVersion() (string, error)
GetStoppable() stoppable.Stoppable
}
type HealthTracker interface {
......
......@@ -33,10 +33,6 @@ import (
// Manager implements the NetworkManager interface inside context. It
// controls access to network resources and implements all of the communications
// functions used by the client.
type Manager struct {
m manager
}
type manager struct {
// parameters of the network
param params.Network
......@@ -53,7 +49,7 @@ type manager struct {
}
// NewManager builds a new reception manager object using inputted key fields
func NewManager(ctx *context.Context, params params.Network, ndf *ndf.NetworkDefinition) (*Manager, error) {
func NewManager(ctx *context.Context, params params.Network, ndf *ndf.NetworkDefinition) (context.NetworkManager, error) {
//get the user from storage
user := ctx.Session.User()
......@@ -97,18 +93,18 @@ func NewManager(ctx *context.Context, params params.Network, ndf *ndf.NetworkDef
m.message = message.NewManager(m.Internal, m.param.Messages, m.NodeRegistration)
m.round = rounds.NewManager(m.Internal, m.param.Rounds, m.message.GetMessageReceptionChannel())
return &Manager{m: m}, nil
return &m, nil
}
// GetRemoteVersion contacts the permissioning server and returns the current
// supported client version.
func (m *Manager) GetRemoteVersion() (string, error) {
permissioningHost, ok := m.m.Comms.GetHost(&id.Permissioning)
func (m *manager) GetRemoteVersion() (string, error) {
permissioningHost, ok := m.Comms.GetHost(&id.Permissioning)
if !ok {
return "", errors.Errorf("no permissioning host with id %s",
id.Permissioning)
}
registrationVersion, err := m.m.Comms.SendGetCurrentClientVersionMessage(
registrationVersion, err := m.Comms.SendGetCurrentClientVersionMessage(
permissioningHost)
if err != nil {
return "", err
......@@ -116,12 +112,8 @@ func (m *Manager) GetRemoteVersion() (string, error) {
return registrationVersion.Version, nil
}
func (m *Manager) StartRunners() error {
return m.m.startRunners()
}
// StartRunners kicks off all network reception goroutines ("threads").
func (m *manager) startRunners() error {
func (m *manager) StartRunners() error {
if m.runners.IsRunning() {
return errors.Errorf("network routines are already running")
}
......@@ -152,34 +144,23 @@ func (m *manager) startRunners() error {
return nil
}
func (m *Manager) RegisterWithPermissioning(registrationCode string) ([]byte, error) {
pubKey := m.m.Session.User().GetCryptographicIdentity().GetRSA().GetPublic()
return permissioning.Register(m.m.Comms, pubKey, registrationCode)
}
// GetRunners returns the network goroutines such that they can be named
// and stopped.
func (m *Manager) GetRunners() stoppable.Stoppable {
return m.m.runners
func (m *manager) RegisterWithPermissioning(registrationCode string) ([]byte, error) {
pubKey := m.Session.User().GetCryptographicIdentity().GetRSA().GetPublic()
return permissioning.Register(m.Comms, pubKey, registrationCode)
}
// StopRunners stops all the reception goroutines
func (m *Manager) GetStoppable() stoppable.Stoppable {
return m.m.runners
func (m *manager) GetStoppable() stoppable.Stoppable {
return m.runners
}
// GetHealthTracker returns the health tracker
func (m *Manager) GetHealthTracker() context.HealthTracker {
return m.m.Health
func (m *manager) GetHealthTracker() context.HealthTracker {
return m.Health
}
// GetInstance returns the network instance object (ndf state)
func (m *Manager) GetInstance() *network.Instance {
return m.m.Instance
func (m *manager) GetInstance() *network.Instance {
return m.Instance
}
// GetNodeRegistrationCh returns node registration channel for node
// events.
func (m *Manager) GetNodeRegistrationCh() chan network.NodeGateway {
return m.m.NodeRegistration
}
......@@ -13,13 +13,13 @@ import (
// 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(msg format.Message, param params.CMIX) (id.Round, error) {
if !m.m.Health.IsRunning() {
func (m *manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, error) {
if !m.Health.IsRunning() {
return 0, errors.New("Cannot send cmix message when the " +
"network is not healthy")
}
return m.m.message.SendCMIX(msg, param)
return m.message.SendCMIX(msg, param)
}
// SendUnsafe sends an unencrypted payload to the provided recipient
......@@ -27,8 +27,8 @@ func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, err
// of the message were sent or an error if it fails.
// NOTE: Do not use this function unless you know what you are doing.
// This function always produces an error message in client logging.
func (m *Manager) SendUnsafe(msg message.Send, param params.Unsafe) ([]id.Round, error) {
if !m.m.Health.IsRunning() {
func (m *manager) SendUnsafe(msg message.Send, param params.Unsafe) ([]id.Round, error) {
if !m.Health.IsRunning() {
return nil, errors.New("cannot send unsafe message when the " +
"network is not healthy")
}
......@@ -43,13 +43,13 @@ func (m *Manager) SendUnsafe(msg message.Send, param params.Unsafe) ([]id.Round,
// 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(msg message.Send, e2eP params.E2E) (
func (m *manager) SendE2E(msg message.Send, e2eP params.E2E) (
[]id.Round, error) {
if !m.m.Health.IsRunning() {
if !m.Health.IsRunning() {
return nil, errors.New("Cannot send e2e message when the " +
"network is not healthy")
}
return m.m.message.SendE2E(msg, e2eP)
return m.message.SendE2E(msg, e2eP)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment