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

a bunch of small fixes

parent f7e09f0c
No related branches found
No related tags found
3 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast
......@@ -26,7 +26,7 @@ import (
// Sender Object used for sending that wraps the HostPool for providing destinations
type Sender interface {
SendToAny(sendFunc func(host *connect.Host) (interface{}, error), stop *stoppable.Single) (interface{}, error)
SendToPreferred(targets []*id.ID, sendFunc sendToPreferredFunc,
SendToPreferred(targets []*id.ID, sendFunc SendToPreferredFunc,
stop *stoppable.Single, timeout time.Duration) (interface{}, error)
UpdateNdf(ndf *ndf.NetworkDefinition)
SetGatewayFilter(f Filter)
......@@ -86,14 +86,14 @@ func (s *sender) SendToAny(sendFunc func(host *connect.Host) (interface{}, error
return nil, errors.Errorf("Unable to send to any proxies")
}
// sendToPreferredFunc is the send function passed into Sender.SendToPreferred.
type sendToPreferredFunc func(host *connect.Host, target *id.ID,
// SendToPreferredFunc is the send function passed into Sender.SendToPreferred.
type SendToPreferredFunc func(host *connect.Host, target *id.ID,
timeout time.Duration) (interface{}, error)
// SendToPreferred Call given sendFunc to any Host in the HostPool, attempting
// with up to numProxies destinations. Returns an error if the timeout is
// reached.
func (s *sender) SendToPreferred(targets []*id.ID, sendFunc sendToPreferredFunc,
func (s *sender) SendToPreferred(targets []*id.ID, sendFunc SendToPreferredFunc,
stop *stoppable.Single, timeout time.Duration) (interface{}, error) {
startTime := netTime.Now()
......
......@@ -17,7 +17,7 @@ import (
func TestNewTracker(t *testing.T) {
// Initialize required variables
timeout := 250 * time.Millisecond
tracker := newTracker(timeout)
trkr := newTracker(timeout)
counter := 2 // First signal is "false/unhealthy"
positiveHb := network.Heartbeat{
HasWaitingRound: true,
......@@ -33,8 +33,8 @@ func TestNewTracker(t *testing.T) {
counter--
}
}
tracker.AddHealthChannelCallback(listenChan)
tracker.AddHealthCallback(listenFunc)
trkr.AddHealthCallback(listenFunc)
trkr.AddHealthCallback(listenFunc)
go func() {
for isHealthy := range listenChan {
if isHealthy {
......@@ -46,18 +46,18 @@ func TestNewTracker(t *testing.T) {
}()
// Begin the health tracker
_, err := tracker.Start()
_, err := trkr.StartProcessies()
if err != nil {
t.Fatalf("Unable to start tracker: %+v", err)
}
// Send a positive health heartbeat
expectedCount := 2
tracker.heartbeat <- positiveHb
trkr.heartbeat <- positiveHb
// Wait for the heartbeat to register
for i := 0; i < 4; i++ {
if tracker.IsHealthy() && counter == expectedCount {
if trkr.IsHealthy() && counter == expectedCount {
break
} else {
time.Sleep(50 * time.Millisecond)
......@@ -65,12 +65,12 @@ func TestNewTracker(t *testing.T) {
}
// Verify the network was marked as healthy
if !tracker.IsHealthy() {
if !trkr.IsHealthy() {
t.Fatal("tracker did not become healthy.")
}
// Check if the tracker was ever healthy
if !tracker.WasHealthy() {
if !trkr.WasHealthy() {
t.Fatal("tracker did not become healthy.")
}
......@@ -84,12 +84,12 @@ func TestNewTracker(t *testing.T) {
time.Sleep(timeout)
// Verify the network was marked as NOT healthy
if tracker.IsHealthy() {
if trkr.IsHealthy() {
t.Fatal("tracker should not report healthy.")
}
// Check if the tracker was ever healthy, after setting healthy to false
if !tracker.WasHealthy() {
if !trkr.WasHealthy() {
t.Fatal("tracker was healthy previously but not reported healthy.")
}
......
......@@ -3,7 +3,6 @@ package receptionID
import (
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/interfaces/params"
"gitlab.com/elixxir/client/network/identity/receptionID/store"
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/xx_network/primitives/id"
......@@ -49,7 +48,7 @@ func newRegistration(reg Identity, kv *versioned.KV) (*registration, error) {
urParams.Stored = !reg.Ephemeral
r.UR = store.NewUnknownRounds(kv, urParams)
r.ER = store.NewEarliestRound(!reg.Ephemeral, kv)
cr, err := store.NewCheckedRounds(int(params.GetDefaultNetwork().KnownRoundsThreshold), kv)
cr, err := store.NewCheckedRounds(1500, kv)
if err != nil {
jww.FATAL.Printf("Failed to create new CheckedRounds for registration: %+v", err)
}
......@@ -79,12 +78,12 @@ func loadRegistration(EphId ephemeral.Id, Source *id.ID, startValid time.Time,
"for %s", regPrefix(EphId, Source, startValid))
}
cr, err := store.LoadCheckedRounds(int(params.GetDefaultNetwork().KnownRoundsThreshold), kv)
cr, err := store.LoadCheckedRounds(1500, kv)
if err != nil {
jww.ERROR.Printf("Making new CheckedRounds, loading of CheckedRounds "+
"failed: %+v", err)
cr, err = store.NewCheckedRounds(int(params.GetDefaultNetwork().KnownRoundsThreshold), kv)
cr, err = store.NewCheckedRounds(1500, kv)
if err != nil {
jww.FATAL.Printf("Failed to create new CheckedRounds for "+
"registration after CheckedRounds load failure: %+v", err)
......
......@@ -15,7 +15,7 @@ import (
"time"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/network/address"
"gitlab.com/elixxir/client/network/identity/receptionID"
"gitlab.com/elixxir/client/stoppable"
......@@ -38,6 +38,9 @@ var Forever = time.Time{}
const trackedIDChanSize = 1000
const deleteIDChanSize = 1000
// DefaultExtraChecks is the default value for ExtraChecks on reception.Identity
const DefaultExtraChecks = 10
type Tracker interface {
StartProcessies() stoppable.Stoppable
AddIdentity(id *id.ID, validUntil time.Time, persistent bool)
......@@ -299,7 +302,7 @@ func generateIdentitiesOverRange(lastGeneration, generateThrough time.Time,
for i, eid := range protoIds {
// Expand the grace period for both start and end
identities[i] = receptionID.Identity{
EphemeralIdentity: interfaces.EphemeralIdentity{
EphemeralIdentity: receptionID.EphemeralIdentity{
EphId: eid.Id,
Source: source,
},
......@@ -308,7 +311,7 @@ func generateIdentitiesOverRange(lastGeneration, generateThrough time.Time,
StartValid: eid.Start.Add(-validityGracePeriod),
EndValid: eid.End.Add(validityGracePeriod),
Ephemeral: false,
ExtraChecks: interfaces.DefaultExtraChecks,
ExtraChecks: DefaultExtraChecks,
}
}
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package identity
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/interfaces"
ephemeral2 "gitlab.com/elixxir/client/network/address"
"gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/testkeys"
"gitlab.com/xx_network/comms/signature"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/netTime"
"gitlab.com/xx_network/primitives/utils"
"testing"
"time"
)
// Smoke test for Track function
func TestCheck(t *testing.T) {
session := storage.InitTestingSession(t)
instance := ephemeral2.NewTestNetworkManager(t)
if err := setupInstance(instance); err != nil {
t.Errorf("Could not set up instance: %+v", err)
}
// Store a mock initial timestamp the store
now := netTime.Now()
twoDaysAgo := now.Add(-2 * 24 * time.Hour)
twoDaysTimestamp, err := marshalTimestamp(twoDaysAgo)
if err != nil {
t.Errorf("Could not marshal timestamp for test setup: %+v", err)
}
err = session.Set(TimestampKey, twoDaysTimestamp)
if err != nil {
t.Errorf("Could not set mock timestamp for test setup: %+v", err)
}
ourId := id.NewIdFromBytes([]byte("Sauron"), t)
stop := Track(session, ephemeral2.NewTestAddressSpace(15, t), ourId)
err = stop.Close()
if err != nil {
t.Errorf("Could not close thread: %+v", err)
}
}
// Unit test for track.
func TestCheck_Thread(t *testing.T) {
session := storage.InitTestingSession(t)
instance := ephemeral2.NewTestNetworkManager(t)
if err := setupInstance(instance); err != nil {
t.Errorf("Could not set up instance: %v", err)
}
ourId := id.NewIdFromBytes([]byte("Sauron"), t)
stop := stoppable.NewSingle(ephemeralStoppable)
// Store a mock initial timestamp the store
now := netTime.Now()
yesterday := now.Add(-24 * time.Hour)
yesterdayTimestamp, err := marshalTimestamp(yesterday)
if err != nil {
t.Errorf("Could not marshal timestamp for test setup: %+v", err)
}
err = session.Set(TimestampKey, yesterdayTimestamp)
if err != nil {
t.Errorf("Could not set mock timestamp for test setup: %+v", err)
}
// Run the tracker
go func() {
track(session, ephemeral2.NewTestAddressSpace(15, t), ourId, stop)
}()
time.Sleep(3 * time.Second)
err = stop.Close()
if err != nil {
t.Errorf("Could not close thread: %v", err)
}
}
func setupInstance(instance interfaces.NetworkManager) error {
cert, err := utils.ReadFile(testkeys.GetNodeKeyPath())
if err != nil {
return errors.Errorf("Failed to read cert from from file: %+v", err)
}
ri := &mixmessages.RoundInfo{
ID: 1,
}
testCert, err := rsa.LoadPrivateKeyFromPem(cert)
if err != nil {
return errors.Errorf("Failed to load cert from from file: %+v", err)
}
if err = signature.SignRsa(ri, testCert); err != nil {
return errors.Errorf("Failed to sign round info: %+v", err)
}
if _, err = instance.GetInstance().RoundUpdate(ri); err != nil {
return errors.Errorf("Failed to RoundUpdate from from file: %+v", err)
}
ri = &mixmessages.RoundInfo{
ID: 2,
}
if err = signature.SignRsa(ri, testCert); err != nil {
return errors.Errorf("Failed to sign round info: %+v", err)
}
if _, err = instance.GetInstance().RoundUpdate(ri); err != nil {
return errors.Errorf("Failed to RoundUpdate from from file: %v", err)
}
return nil
}
func TestGenerateIdentities(t *testing.T) {
eid, s, e, err := ephemeral.GetId(id.NewIdFromString("zezima", id.Node, t), 16, time.Now().UnixNano())
if err != nil {
t.Errorf("Failed to get eid: %+v", err)
}
protoIds := []ephemeral.ProtoIdentity{{eid, s, e}}
generated := generateIdentities(protoIds, id.NewIdFromString("escaline", id.Node, t), 16)
if generated[0].EndValid != protoIds[0].End.Add(5*time.Minute) {
t.Errorf("End was not modified. Orig %+v, Generated %+v", protoIds[0].End, generated[0].End)
}
if generated[0].StartValid != protoIds[0].Start.Add(-5*time.Minute) {
t.Errorf("End was not modified. Orig %+v, Generated %+v", protoIds[0].End, generated[0].End)
}
}
package network
import (
"gitlab.com/elixxir/client/network/gateway"
"gitlab.com/elixxir/client/network/historical"
"gitlab.com/elixxir/client/network/message"
"gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/ndf"
"time"
)
......@@ -45,7 +45,8 @@ type Manager interface {
// Will return an error if the network is unhealthy or if it fails to send
// (along with the reason). Blocks until successful send or err.
// WARNING: Do not roll your own crypto
SendCMIX(message format.Message, recipient *id.ID, p CMIXParams) (
SendCMIX(recipient *id.ID, fingerprint format.Fingerprint,
service message.Service, payload, mac []byte, cmixParams CMIXParams) (
id.Round, ephemeral.Id, error)
// SendManyCMIX sends many "raw" CMIX message payloads to the provided
......@@ -84,7 +85,7 @@ type Manager interface {
// 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
AddIdentity(id *id.ID, validUntil time.Time, persistent bool)
// RemoveIdentity removes a currently tracked identity.
RemoveIdentity(id *id.ID)
......@@ -207,8 +208,7 @@ type Manager interface {
// LookupHistoricalRound - looks up the passed historical round on the
// network
LookupHistoricalRound(rid id.Round, callback func(info *mixmessages.RoundInfo,
success bool)) error
LookupHistoricalRound(rid id.Round, callback historical.RoundResultCallback) error
/*===Sender===============================================================*/
/* The sender handles sending comms to the network. It tracks connections to
......@@ -217,18 +217,17 @@ type Manager interface {
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)
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),
SendToPreferred(targets []*id.ID, sendFunc gateway.SendToPreferredFunc,
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)
SetGatewayFilter(f gateway.Filter)
// GetHostParams - returns the host params used when connectign to gateways
GetHostParams() connect.HostParams
......
......@@ -9,12 +9,12 @@ package rounds
import (
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/network/identity/receptionID"
pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/xx_network/primitives/id"
)
func (m *manager) GetMessagesFromRound(roundID id.Round, identity interfaces.EphemeralIdentity) {
func (m *manager) GetMessagesFromRound(roundID id.Round, identity receptionID.EphemeralIdentity) {
//get the round from the in ram store
ri, err := m.instance.GetRound(roundID)
......
package network
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/interfaces/params"
"gitlab.com/elixxir/client/network/gateway"
message2 "gitlab.com/elixxir/client/network/message"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/client/switchboard"
"gitlab.com/elixxir/comms/client"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/network"
ds "gitlab.com/elixxir/comms/network/dataStructures"
"gitlab.com/elixxir/comms/testutils"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/e2e"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/elixxir/primitives/format"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime"
"testing"
"time"
)
/*
type dummyEvent struct{}
func (e *dummyEvent) Report(priority int, category, evtType, details string) {}
......@@ -125,4 +100,4 @@ func Test_attemptSendCmix(t *testing.T) {
panic("t")
return
}
}
}*/
package network
/*
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/client/interfaces/message"
......@@ -137,4 +138,4 @@ func Test_attemptSendManyCmix(t *testing.T) {
if err != nil {
t.Errorf("Failed to sendcmix: %+v", err)
}
}
}*/
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