Skip to content
Snippets Groups Projects
Commit ff525975 authored by Josh Brooks's avatar Josh Brooks
Browse files

Merge branch 'release' of gitlab.com:elixxir/client into feature/DeleteContact

parents 0382adba 3ebb6ae3
Branches
Tags
1 merge request!23Release
...@@ -30,6 +30,7 @@ import ( ...@@ -30,6 +30,7 @@ import (
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf" "gitlab.com/xx_network/primitives/ndf"
"math"
"sync" "sync"
"time" "time"
) )
...@@ -235,6 +236,8 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie ...@@ -235,6 +236,8 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie
if def.Notification.Address != "" { if def.Notification.Address != "" {
hp := connect.GetDefaultHostParams() hp := connect.GetDefaultHostParams()
// Client will not send KeepAlive packets
hp.KaClientOpts.Time = time.Duration(math.MaxInt64)
hp.AuthEnabled = false hp.AuthEnabled = false
hp.MaxRetries = 5 hp.MaxRetries = 5
_, err = c.comms.AddHost(&id.NotificationBot, def.Notification.Address, []byte(def.Notification.TlsCertificate), hp) _, err = c.comms.AddHost(&id.NotificationBot, def.Notification.Address, []byte(def.Notification.TlsCertificate), hp)
...@@ -396,7 +399,6 @@ func (c *Client) StartNetworkFollower(timeout time.Duration) (<-chan interfaces. ...@@ -396,7 +399,6 @@ func (c *Client) StartNetworkFollower(timeout time.Duration) (<-chan interfaces.
return nil, errors.Errorf("Cannot Stop the Network Follower when it is not running, status: %s", status) return nil, errors.Errorf("Cannot Stop the Network Follower when it is not running, status: %s", status)
} }
c.clientErrorChannel = make(chan interfaces.ClientError, 1000) c.clientErrorChannel = make(chan interfaces.ClientError, 1000)
cer := func(source, message, trace string) { cer := func(source, message, trace string) {
......
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at // This file was generated by robots at
// 2021-05-24 13:15:09.546928 -0500 CDT m=+0.071553794 // 2021-06-22 11:16:35.397077 -0500 CDT m=+0.025546669
package api package api
const GITVERSION = `c85adeb9 Merge branch 'Anne/CI2' into 'release'` const GITVERSION = `b7692cd7 added Keepalive opts`
const SEMVER = "2.7.0" const SEMVER = "2.7.0"
const DEPENDENCIES = `module gitlab.com/elixxir/client const DEPENDENCIES = `module gitlab.com/elixxir/client
...@@ -11,7 +11,7 @@ go 1.13 ...@@ -11,7 +11,7 @@ go 1.13
require ( require (
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/protobuf v1.4.3 github.com/golang/protobuf v1.5.2
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/magiconair/properties v1.8.4 // indirect github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/mapstructure v1.4.0 // indirect github.com/mitchellh/mapstructure v1.4.0 // indirect
...@@ -24,21 +24,18 @@ require ( ...@@ -24,21 +24,18 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/viper v1.7.1 github.com/spf13/viper v1.7.1
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20210524170509-89dd425cb228 gitlab.com/elixxir/comms v0.0.4-0.20210622161439-b694033c9507
gitlab.com/elixxir/crypto v0.0.7-0.20210524170447-264b215ce90b gitlab.com/elixxir/crypto v0.0.7-0.20210614155844-c1e9c23a6ba7
gitlab.com/elixxir/ekv v0.1.5 gitlab.com/elixxir/ekv v0.1.5
gitlab.com/elixxir/primitives v0.0.3-0.20210524170524-9780695d2b55 gitlab.com/elixxir/primitives v0.0.3-0.20210614155726-ebcf2d47a527
gitlab.com/xx_network/comms v0.0.4-0.20210524170426-175f698a7b07 gitlab.com/xx_network/comms v0.0.4-0.20210622161535-4f3d927d4c8c
gitlab.com/xx_network/crypto v0.0.5-0.20210524170434-dc9a398a2581 gitlab.com/xx_network/crypto v0.0.5-0.20210614155554-8c333814205b
gitlab.com/xx_network/primitives v0.0.4-0.20210524170438-ab712af183db gitlab.com/xx_network/primitives v0.0.4-0.20210617180018-6472489fd418
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 golang.org/x/net v0.0.0-20210525063256-abc453219eb5
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 // indirect
google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1 // indirect google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1 // indirect
google.golang.org/grpc v1.34.0 // indirect google.golang.org/protobuf v1.26.0
google.golang.org/protobuf v1.26.0-rc.1
gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
) )
replace google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1
` `
...@@ -232,7 +232,7 @@ func (c *Client) StopNetworkFollower() error { ...@@ -232,7 +232,7 @@ func (c *Client) StopNetworkFollower() error {
func (c *Client) WaitForNetwork(timeoutMS int) bool { func (c *Client) WaitForNetwork(timeoutMS int) bool {
start := netTime.Now() start := netTime.Now()
timeout := time.Duration(timeoutMS) * time.Millisecond timeout := time.Duration(timeoutMS) * time.Millisecond
for netTime.Now().Sub(start) < timeout { for netTime.Since(start) < timeout {
if c.api.GetHealth().IsHealthy() { if c.api.GetHealth().IsHealthy() {
return true return true
} }
...@@ -256,10 +256,15 @@ func (c *Client) IsNetworkHealthy() bool { ...@@ -256,10 +256,15 @@ func (c *Client) IsNetworkHealthy() bool {
return c.api.GetHealth().IsHealthy() return c.api.GetHealth().IsHealthy()
} }
// registers the network health callback to be called any time the network // RegisterNetworkHealthCB registers the network health callback to be called
// health changes // any time the network health changes. Returns a unique ID that can be used to
func (c *Client) RegisterNetworkHealthCB(nhc NetworkHealthCallback) { // unregister the network health callback.
c.api.GetHealth().AddFunc(nhc.Callback) func (c *Client) RegisterNetworkHealthCB(nhc NetworkHealthCallback) int64 {
return int64(c.api.GetHealth().AddFunc(nhc.Callback))
}
func (c *Client) UnregisterNetworkHealthCB(funcID int64) {
c.api.GetHealth().RemoveFunc(uint64(funcID))
} }
// RegisterListener records and installs a listener for messages // RegisterListener records and installs a listener for messages
......
...@@ -17,13 +17,13 @@ require ( ...@@ -17,13 +17,13 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/viper v1.7.1 github.com/spf13/viper v1.7.1
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20210614160131-de90e88a68cc gitlab.com/elixxir/comms v0.0.4-0.20210622161439-b694033c9507
gitlab.com/elixxir/crypto v0.0.7-0.20210614155844-c1e9c23a6ba7 gitlab.com/elixxir/crypto v0.0.7-0.20210614155844-c1e9c23a6ba7
gitlab.com/elixxir/ekv v0.1.5 gitlab.com/elixxir/ekv v0.1.5
gitlab.com/elixxir/primitives v0.0.3-0.20210614155726-ebcf2d47a527 gitlab.com/elixxir/primitives v0.0.3-0.20210614155726-ebcf2d47a527
gitlab.com/xx_network/comms v0.0.4-0.20210614155654-191473de2702 gitlab.com/xx_network/comms v0.0.4-0.20210622161535-4f3d927d4c8c
gitlab.com/xx_network/crypto v0.0.5-0.20210614155554-8c333814205b gitlab.com/xx_network/crypto v0.0.5-0.20210614155554-8c333814205b
gitlab.com/xx_network/primitives v0.0.4-0.20210608160426-670aab2d82cf gitlab.com/xx_network/primitives v0.0.4-0.20210617180018-6472489fd418
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 golang.org/x/net v0.0.0-20210525063256-abc453219eb5
google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1 // indirect google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1 // indirect
......
...@@ -247,8 +247,8 @@ github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0= ...@@ -247,8 +247,8 @@ github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0=
github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0BJIk1HIzBVMjWNjIUfstrsXC2VqLYPcA= gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0BJIk1HIzBVMjWNjIUfstrsXC2VqLYPcA=
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k=
gitlab.com/elixxir/comms v0.0.4-0.20210614160131-de90e88a68cc h1:MB+Ixmz/0eWt2akBYajjH2h53GF0NjWn4Oy4Q7x4QVg= gitlab.com/elixxir/comms v0.0.4-0.20210622161439-b694033c9507 h1:uH64CKk3PVzo0v9FbII3XYNiZIoQz2pOb7Fnu5L/Ba8=
gitlab.com/elixxir/comms v0.0.4-0.20210614160131-de90e88a68cc/go.mod h1:JeCKUXRS9xP3YYGPl4+OMFdvtt7ySJIxEsL9AzgeCu0= gitlab.com/elixxir/comms v0.0.4-0.20210622161439-b694033c9507/go.mod h1:vVAO+8dSm/sikL66Qx/+CEBVVzzDIdYru+VLcrIm+tA=
gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/crypto v0.0.7-0.20210614155844-c1e9c23a6ba7 h1:UBq4/xMUWkYmEzUN2F7nLw5qQeiNKoLaoX3vZ/flz1c= gitlab.com/elixxir/crypto v0.0.7-0.20210614155844-c1e9c23a6ba7 h1:UBq4/xMUWkYmEzUN2F7nLw5qQeiNKoLaoX3vZ/flz1c=
...@@ -262,8 +262,9 @@ gitlab.com/elixxir/primitives v0.0.1/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2Y ...@@ -262,8 +262,9 @@ gitlab.com/elixxir/primitives v0.0.1/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2Y
gitlab.com/elixxir/primitives v0.0.3-0.20210614155726-ebcf2d47a527 h1:kBNAGFy5Ylz7F0K3DmyzuHLf1npBg7a3t4qKvfqPL3Y= gitlab.com/elixxir/primitives v0.0.3-0.20210614155726-ebcf2d47a527 h1:kBNAGFy5Ylz7F0K3DmyzuHLf1npBg7a3t4qKvfqPL3Y=
gitlab.com/elixxir/primitives v0.0.3-0.20210614155726-ebcf2d47a527/go.mod h1:nSmBXcw4hkBLFdhu+araAPvf9szCDQF1fpRZ9/BgBec= gitlab.com/elixxir/primitives v0.0.3-0.20210614155726-ebcf2d47a527/go.mod h1:nSmBXcw4hkBLFdhu+araAPvf9szCDQF1fpRZ9/BgBec=
gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw= gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw=
gitlab.com/xx_network/comms v0.0.4-0.20210614155654-191473de2702 h1:ydi8FaAjFGfxMcvmIGlvnng491K2uEl3ymALC2Hh8Vw= gitlab.com/xx_network/comms v0.0.4-0.20210617183321-d5f4fd71033c/go.mod h1:ehwxZxcAQHkJjP5BNkwPNK8/o6avUn0j0iDDiu+nMFc=
gitlab.com/xx_network/comms v0.0.4-0.20210614155654-191473de2702/go.mod h1:ehwxZxcAQHkJjP5BNkwPNK8/o6avUn0j0iDDiu+nMFc= gitlab.com/xx_network/comms v0.0.4-0.20210622161535-4f3d927d4c8c h1:/vUWvCEGL9dI73Cv0eRIxgYnicSCwXYduV6PJVcdsus=
gitlab.com/xx_network/comms v0.0.4-0.20210622161535-4f3d927d4c8c/go.mod h1:ehwxZxcAQHkJjP5BNkwPNK8/o6avUn0j0iDDiu+nMFc=
gitlab.com/xx_network/crypto v0.0.3/go.mod h1:DF2HYvvCw9wkBybXcXAgQMzX+MiGbFPjwt3t17VRqRE= gitlab.com/xx_network/crypto v0.0.3/go.mod h1:DF2HYvvCw9wkBybXcXAgQMzX+MiGbFPjwt3t17VRqRE=
gitlab.com/xx_network/crypto v0.0.4/go.mod h1:+lcQEy+Th4eswFgQDwT0EXKp4AXrlubxalwQFH5O0Mk= gitlab.com/xx_network/crypto v0.0.4/go.mod h1:+lcQEy+Th4eswFgQDwT0EXKp4AXrlubxalwQFH5O0Mk=
gitlab.com/xx_network/crypto v0.0.5-0.20210614155554-8c333814205b h1:X2Hhg9/IYowxMdI6TTnWj6WW3pnO2vMB/7f4mnu6Muw= gitlab.com/xx_network/crypto v0.0.5-0.20210614155554-8c333814205b h1:X2Hhg9/IYowxMdI6TTnWj6WW3pnO2vMB/7f4mnu6Muw=
...@@ -271,8 +272,9 @@ gitlab.com/xx_network/crypto v0.0.5-0.20210614155554-8c333814205b/go.mod h1:wiaQ ...@@ -271,8 +272,9 @@ gitlab.com/xx_network/crypto v0.0.5-0.20210614155554-8c333814205b/go.mod h1:wiaQ
gitlab.com/xx_network/primitives v0.0.0-20200803231956-9b192c57ea7c/go.mod h1:wtdCMr7DPePz9qwctNoAUzZtbOSHSedcK++3Df3psjA= gitlab.com/xx_network/primitives v0.0.0-20200803231956-9b192c57ea7c/go.mod h1:wtdCMr7DPePz9qwctNoAUzZtbOSHSedcK++3Df3psjA=
gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da/go.mod h1:OK9xevzWCaPO7b1wiluVJGk7R5ZsuC7pHY5hteZFQug= gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da/go.mod h1:OK9xevzWCaPO7b1wiluVJGk7R5ZsuC7pHY5hteZFQug=
gitlab.com/xx_network/primitives v0.0.2/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc= gitlab.com/xx_network/primitives v0.0.2/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc=
gitlab.com/xx_network/primitives v0.0.4-0.20210608160426-670aab2d82cf h1:4snRmLHx/mgbdMtuXT2ITxyCElgvlOd7bJA1QSx0aI4=
gitlab.com/xx_network/primitives v0.0.4-0.20210608160426-670aab2d82cf/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE= gitlab.com/xx_network/primitives v0.0.4-0.20210608160426-670aab2d82cf/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE=
gitlab.com/xx_network/primitives v0.0.4-0.20210617180018-6472489fd418 h1:F52R0wvFobjkmB8YaPNHZIu0VYqwjesMBCb9T14ygW8=
gitlab.com/xx_network/primitives v0.0.4-0.20210617180018-6472489fd418/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE=
gitlab.com/xx_network/ring v0.0.3-0.20210527191221-ce3f170aabd5 h1:FY+4Rh1Q2rgLyv10aKJjhWApuKRCR/054XhreudfAvw= gitlab.com/xx_network/ring v0.0.3-0.20210527191221-ce3f170aabd5 h1:FY+4Rh1Q2rgLyv10aKJjhWApuKRCR/054XhreudfAvw=
gitlab.com/xx_network/ring v0.0.3-0.20210527191221-ce3f170aabd5/go.mod h1:aLzpP2TiZTQut/PVHR40EJAomzugDdHXetbieRClXIM= gitlab.com/xx_network/ring v0.0.3-0.20210527191221-ce3f170aabd5/go.mod h1:aLzpP2TiZTQut/PVHR40EJAomzugDdHXetbieRClXIM=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
......
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
package interfaces package interfaces
type HealthTracker interface { type HealthTracker interface {
AddChannel(chan bool) AddChannel(chan bool) uint64
AddFunc(f func(bool)) RemoveChannel(uint64)
AddFunc(f func(bool)) uint64
RemoveFunc(uint64)
IsHealthy() bool IsHealthy() bool
WasHealthy() bool WasHealthy() bool
} }
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
// LICENSE file // // LICENSE file //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Contains functionality related to the event model driven network health tracker // Contains functionality related to the event model driven network health
// tracker.
package health package health
...@@ -23,70 +24,108 @@ type Tracker struct { ...@@ -23,70 +24,108 @@ type Tracker struct {
heartbeat chan network.Heartbeat heartbeat chan network.Heartbeat
channels []chan bool channels map[uint64]chan bool
funcs []func(isHealthy bool) funcs map[uint64]func(isHealthy bool)
channelsID uint64
funcsID uint64
running bool running bool
// Determines the current health status // Determines the current health status
isHealthy bool isHealthy bool
// Denotes the past health status
// wasHealthy is true if isHealthy has ever been true // Denotes that the past health status wasHealthy is true if isHealthy has
// ever been true
wasHealthy bool wasHealthy bool
mux sync.RWMutex mux sync.RWMutex
} }
// Creates a single HealthTracker thread, starts it, and returns a tracker and a stoppable // Init creates a single HealthTracker thread, starts it, and returns a tracker
// and a stoppable.
func Init(instance *network.Instance, timeout time.Duration) *Tracker { func Init(instance *network.Instance, timeout time.Duration) *Tracker {
tracker := newTracker(timeout) tracker := newTracker(timeout)
instance.SetNetworkHealthChan(tracker.heartbeat) instance.SetNetworkHealthChan(tracker.heartbeat)
return tracker return tracker
} }
// Builds and returns a new Tracker object given a Context // newTracker builds and returns a new Tracker object given a Context.
func newTracker(timeout time.Duration) *Tracker { func newTracker(timeout time.Duration) *Tracker {
return &Tracker{ return &Tracker{
timeout: timeout, timeout: timeout,
channels: make([]chan bool, 0), channels: map[uint64]chan bool{},
funcs: map[uint64]func(isHealthy bool){},
heartbeat: make(chan network.Heartbeat, 100), heartbeat: make(chan network.Heartbeat, 100),
isHealthy: false, isHealthy: false,
running: false, running: false,
} }
} }
// Add a channel to the list of Tracker channels // AddChannel adds a channel to the list of Tracker channels such that each
// such that each channel can be notified of network changes // channel can be notified of network changes. Returns a unique ID for the
func (t *Tracker) AddChannel(c chan bool) { // channel.
func (t *Tracker) AddChannel(c chan bool) uint64 {
var currentID uint64
t.mux.Lock() t.mux.Lock()
t.channels = append(t.channels, c) t.channels[t.channelsID] = c
currentID = t.channelsID
t.channelsID++
t.mux.Unlock() t.mux.Unlock()
select { select {
case c <- t.IsHealthy(): case c <- t.IsHealthy():
default: default:
} }
return currentID
} }
// Add a function to the list of Tracker function // RemoveChannel removes the channel with the given ID from the list of Tracker
// such that each function can be run after network changes // channels so that it will not longer be notified of network changes.
func (t *Tracker) AddFunc(f func(isHealthy bool)) { func (t *Tracker) RemoveChannel(chanID uint64) {
t.mux.Lock() t.mux.Lock()
t.funcs = append(t.funcs, f) delete(t.channels, chanID)
t.mux.Unlock() t.mux.Unlock()
}
// AddFunc adds a function to the list of Tracker functions such that each
// function can be run after network changes. Returns a unique ID for the
// function.
func (t *Tracker) AddFunc(f func(isHealthy bool)) uint64 {
var currentID uint64
t.mux.Lock()
t.funcs[t.funcsID] = f
currentID = t.funcsID
t.funcsID++
t.mux.Unlock()
go f(t.IsHealthy()) go f(t.IsHealthy())
return currentID
}
// RemoveFunc removes the function with the given ID from the list of Tracker
// functions so that it will not longer be run.
func (t *Tracker) RemoveFunc(chanID uint64) {
t.mux.Lock()
delete(t.channels, chanID)
t.mux.Unlock()
} }
func (t *Tracker) IsHealthy() bool { func (t *Tracker) IsHealthy() bool {
t.mux.RLock() t.mux.RLock()
defer t.mux.RUnlock() defer t.mux.RUnlock()
return t.isHealthy return t.isHealthy
} }
// Returns true if isHealthy has ever been true // WasHealthy returns true if isHealthy has ever been true.
func (t *Tracker) WasHealthy() bool { func (t *Tracker) WasHealthy() bool {
t.mux.RLock() t.mux.RLock()
defer t.mux.RUnlock() defer t.mux.RUnlock()
return t.wasHealthy return t.wasHealthy
} }
...@@ -94,10 +133,11 @@ func (t *Tracker) setHealth(h bool) { ...@@ -94,10 +133,11 @@ func (t *Tracker) setHealth(h bool) {
t.mux.Lock() t.mux.Lock()
// Only set wasHealthy to true if either // Only set wasHealthy to true if either
// wasHealthy is true or // wasHealthy is true or
// wasHealthy false but h value is true // wasHealthy is false but h value is true
t.wasHealthy = t.wasHealthy || h t.wasHealthy = t.wasHealthy || h
t.isHealthy = h t.isHealthy = h
t.mux.Unlock() t.mux.Unlock()
t.transmit(h) t.transmit(h)
} }
...@@ -119,7 +159,8 @@ func (t *Tracker) Start() (stoppable.Stoppable, error) { ...@@ -119,7 +159,8 @@ func (t *Tracker) Start() (stoppable.Stoppable, error) {
return stop, nil return stop, nil
} }
// Long-running thread used to monitor and report on network health // start starts a long-running thread used to monitor and report on network
// health.
func (t *Tracker) start(stop *stoppable.Single) { func (t *Tracker) start(stop *stoppable.Single) {
timer := time.NewTimer(t.timeout) timer := time.NewTimer(t.timeout)
...@@ -131,8 +172,10 @@ func (t *Tracker) start(stop *stoppable.Single) { ...@@ -131,8 +172,10 @@ func (t *Tracker) start(stop *stoppable.Single) {
t.isHealthy = false t.isHealthy = false
t.running = false t.running = false
t.mux.Unlock() t.mux.Unlock()
t.transmit(false) t.transmit(false)
stop.ToStopped() stop.ToStopped()
return return
case heartbeat = <-t.heartbeat: case heartbeat = <-t.heartbeat:
if healthy(heartbeat) { if healthy(heartbeat) {
......
...@@ -9,12 +9,11 @@ package health ...@@ -9,12 +9,11 @@ package health
import ( import (
"gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/comms/network"
// "gitlab.com/elixxir/comms/network"
"testing" "testing"
"time" "time"
) )
// Happy path smoke test // Happy path smoke test.
func TestNewTracker(t *testing.T) { func TestNewTracker(t *testing.T) {
// Initialize required variables // Initialize required variables
timeout := 250 * time.Millisecond timeout := 250 * time.Millisecond
...@@ -49,8 +48,7 @@ func TestNewTracker(t *testing.T) { ...@@ -49,8 +48,7 @@ func TestNewTracker(t *testing.T) {
// Begin the health tracker // Begin the health tracker
_, err := tracker.Start() _, err := tracker.Start()
if err != nil { if err != nil {
t.Errorf("Unable to start tracker: %+v", err) t.Fatalf("Unable to start tracker: %+v", err)
return
} }
// Send a positive health heartbeat // Send a positive health heartbeat
...@@ -68,14 +66,12 @@ func TestNewTracker(t *testing.T) { ...@@ -68,14 +66,12 @@ func TestNewTracker(t *testing.T) {
// Verify the network was marked as healthy // Verify the network was marked as healthy
if !tracker.IsHealthy() { if !tracker.IsHealthy() {
t.Errorf("Tracker did not become healthy") t.Fatal("Tracker did not become healthy.")
return
} }
// Check if the tracker was ever healthy // Check if the tracker was ever healthy
if !tracker.WasHealthy() { if !tracker.WasHealthy() {
t.Errorf("Tracker did not become healthy") t.Fatal("Tracker did not become healthy.")
return
} }
// Verify the heartbeat triggered the listening chan/func // Verify the heartbeat triggered the listening chan/func
...@@ -89,15 +85,12 @@ func TestNewTracker(t *testing.T) { ...@@ -89,15 +85,12 @@ func TestNewTracker(t *testing.T) {
// Verify the network was marked as NOT healthy // Verify the network was marked as NOT healthy
if tracker.IsHealthy() { if tracker.IsHealthy() {
t.Errorf("Tracker should not report healthy") t.Fatal("Tracker should not report healthy.")
return
} }
// Check if the tracker was ever healthy, // Check if the tracker was ever healthy, after setting healthy to false
// after setting healthy to false
if !tracker.WasHealthy() { if !tracker.WasHealthy() {
t.Errorf("Tracker was healthy previously but not reported healthy") t.Fatal("Tracker was healthy previously but not reported healthy.")
return
} }
// Verify the timeout triggered the listening chan/func // Verify the timeout triggered the listening chan/func
......
...@@ -28,6 +28,8 @@ import ( ...@@ -28,6 +28,8 @@ import (
"gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/xx_network/primitives/ndf" "gitlab.com/xx_network/primitives/ndf"
"math"
"time"
) )
// Manager implements the NetworkManager interface inside context. It // Manager implements the NetworkManager interface inside context. It
...@@ -95,6 +97,8 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard, ...@@ -95,6 +97,8 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard,
// Set up gateway.Sender // Set up gateway.Sender
poolParams := gateway.DefaultPoolParams() poolParams := gateway.DefaultPoolParams()
// Client will not send KeepAlive packets
poolParams.HostParams.KaClientOpts.Time = time.Duration(math.MaxInt64)
m.sender, err = gateway.NewSender(poolParams, rng, m.sender, err = gateway.NewSender(poolParams, rng,
ndf, comms, session, m.NodeRegistration) ndf, comms, session, m.NodeRegistration)
if err != nil { if err != nil {
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
"gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"time" "gitlab.com/xx_network/primitives/netTime"
) )
// Messages can arrive in the network out of order. When message handling fails // Messages can arrive in the network out of order. When message handling fails
...@@ -81,7 +81,7 @@ func (m *Manager) handleGarbledMessages() { ...@@ -81,7 +81,7 @@ func (m *Manager) handleGarbledMessages() {
// unless it is the last attempts and has been in the buffer long // unless it is the last attempts and has been in the buffer long
// enough, in which case remove it // enough, in which case remove it
if count == m.param.MaxChecksGarbledMessage && if count == m.param.MaxChecksGarbledMessage &&
time.Since(timestamp) > m.param.GarbledMessageWait { netTime.Since(timestamp) > m.param.GarbledMessageWait {
garbledMsgs.Remove(grbldMsg) garbledMsgs.Remove(grbldMsg)
} else { } else {
failedMsgs = append(failedMsgs, grbldMsg) failedMsgs = append(failedMsgs, grbldMsg)
......
...@@ -57,7 +57,7 @@ func sendCmixHelper(sender *gateway.Sender, msg format.Message, ...@@ -57,7 +57,7 @@ func sendCmixHelper(sender *gateway.Sender, msg format.Message,
"(msgDigest: %s)", recipient, msg.Digest()) "(msgDigest: %s)", recipient, msg.Digest())
for numRoundTries := uint(0); numRoundTries < cmixParams.RoundTries; numRoundTries++ { for numRoundTries := uint(0); numRoundTries < cmixParams.RoundTries; numRoundTries++ {
elapsed := netTime.Now().Sub(timeStart) elapsed := netTime.Since(timeStart)
if elapsed > cmixParams.Timeout { if elapsed > cmixParams.Timeout {
jww.INFO.Printf("No rounds to send to %s (msgDigest: %s) "+ jww.INFO.Printf("No rounds to send to %s (msgDigest: %s) "+
...@@ -73,11 +73,15 @@ func sendCmixHelper(sender *gateway.Sender, msg format.Message, ...@@ -73,11 +73,15 @@ func sendCmixHelper(sender *gateway.Sender, msg format.Message,
remainingTime := cmixParams.Timeout - elapsed remainingTime := cmixParams.Timeout - elapsed
//find the best round to send to, excluding attempted rounds //find the best round to send to, excluding attempted rounds
bestRound, _ := instance.GetWaitingRounds().GetUpcomingRealtime(remainingTime, attempted, sendTimeBuffer) bestRound, err := instance.GetWaitingRounds().GetUpcomingRealtime(remainingTime, attempted, sendTimeBuffer)
if err!=nil{
jww.WARN.Printf("Failed to GetUpcomingRealtime (msgDigest: %s): %+v", msg.Digest(), err)
}
if bestRound == nil { if bestRound == nil {
continue continue
} }
//add the round on to the list of attempted so it is not tried again //add the round on to the list of attempted so it is not tried again
attempted.Insert(bestRound) attempted.Insert(bestRound)
......
...@@ -32,8 +32,8 @@ type sendCmixCommsInterface interface { ...@@ -32,8 +32,8 @@ type sendCmixCommsInterface interface {
SendPutManyMessages(host *connect.Host, messages *pb.GatewaySlots) (*pb.GatewaySlotResponse, error) SendPutManyMessages(host *connect.Host, messages *pb.GatewaySlots) (*pb.GatewaySlotResponse, error)
} }
// 2.5 seconds // how much in the future a round needs to be to send to it
const sendTimeBuffer = 2500 * time.Millisecond const sendTimeBuffer = 1000 * time.Millisecond
const unrecoverableError = "failed with an unrecoverable error" const unrecoverableError = "failed with an unrecoverable error"
// handlePutMessageError handles errors received from a PutMessage or a // handlePutMessageError handles errors received from a PutMessage or a
......
...@@ -71,7 +71,7 @@ func sendManyCmixHelper(sender *gateway.Sender, msgs map[id.ID]format.Message, ...@@ -71,7 +71,7 @@ func sendManyCmixHelper(sender *gateway.Sender, msgs map[id.ID]format.Message,
"(msgDigest: %s)", recipientString, msgDigests) "(msgDigest: %s)", recipientString, msgDigests)
for numRoundTries := uint(0); numRoundTries < param.RoundTries; numRoundTries++ { for numRoundTries := uint(0); numRoundTries < param.RoundTries; numRoundTries++ {
elapsed := netTime.Now().Sub(timeStart) elapsed := netTime.Since(timeStart)
if elapsed > param.Timeout { if elapsed > param.Timeout {
jww.INFO.Printf("No rounds to send to %s (msgDigest: %s) were found "+ jww.INFO.Printf("No rounds to send to %s (msgDigest: %s) were found "+
......
...@@ -13,6 +13,8 @@ import ( ...@@ -13,6 +13,8 @@ import (
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf" "gitlab.com/xx_network/primitives/ndf"
"math"
"time"
) )
type Permissioning struct { type Permissioning struct {
...@@ -31,7 +33,8 @@ func Init(comms *client.Comms, def *ndf.NetworkDefinition) (*Permissioning, erro ...@@ -31,7 +33,8 @@ func Init(comms *client.Comms, def *ndf.NetworkDefinition) (*Permissioning, erro
//add the permissioning host to comms //add the permissioning host to comms
hParam := connect.GetDefaultHostParams() hParam := connect.GetDefaultHostParams()
hParam.AuthEnabled = false hParam.AuthEnabled = false
// Client will not send KeepAlive packets
hParam.KaClientOpts.Time = time.Duration(math.MaxInt64)
perm.host, err = comms.AddHost(&id.Permissioning, def.Registration.Address, perm.host, err = comms.AddHost(&id.Permissioning, def.Registration.Address,
[]byte(def.Registration.TlsCertificate), hParam) []byte(def.Registration.TlsCertificate), hParam)
......
...@@ -138,7 +138,7 @@ func (m *Manager) transmitSingleUse(partner contact2.Contact, payload []byte, ...@@ -138,7 +138,7 @@ func (m *Manager) transmitSingleUse(partner contact2.Contact, payload []byte,
} }
// Update the timeout for the elapsed time // Update the timeout for the elapsed time
roundEventTimeout := timeout - netTime.Now().Sub(timeStart) - time.Millisecond roundEventTimeout := timeout - netTime.Since(timeStart) - time.Millisecond
// Check message delivery // Check message delivery
sendResults := make(chan ds.EventReturn, 1) sendResults := make(chan ds.EventReturn, 1)
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"math"
"time" "time"
) )
...@@ -50,9 +51,9 @@ type Manager struct { ...@@ -50,9 +51,9 @@ type Manager struct {
// updated NDF is available and will error if one is not. // updated NDF is available and will error if one is not.
func NewManager(client *api.Client, single *single.Manager) (*Manager, error) { func NewManager(client *api.Client, single *single.Manager) (*Manager, error) {
jww.INFO.Println("ud.NewManager()") jww.INFO.Println("ud.NewManager()")
if !client.GetHealth().IsHealthy() { if client.NetworkFollowerStatus() != api.Running {
return nil, errors.New("cannot start UD Manager when network was " + return nil, errors.New("cannot start UD Manager when network follower is not " +
"never healthy.") "running.")
} }
m := &Manager{ m := &Manager{
...@@ -89,6 +90,8 @@ func NewManager(client *api.Client, single *single.Manager) (*Manager, error) { ...@@ -89,6 +90,8 @@ func NewManager(client *api.Client, single *single.Manager) (*Manager, error) {
// Create the user discovery host object // Create the user discovery host object
hp := connect.GetDefaultHostParams() hp := connect.GetDefaultHostParams()
// Client will not send KeepAlive packets
hp.KaClientOpts.Time = time.Duration(math.MaxInt64)
hp.MaxRetries = 3 hp.MaxRetries = 3
hp.SendTimeout = 3 * time.Second hp.SendTimeout = 3 * time.Second
m.host, err = m.comms.AddHost(&id.UDB, def.UDB.Address, []byte(def.UDB.Cert), hp) m.host, err = m.comms.AddHost(&id.UDB, def.UDB.Address, []byte(def.UDB.Cert), hp)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment