diff --git a/api/client.go b/api/client.go index 2fb0ee6910bc34a2501e8f79727230493b7e9d61..e70241ec757547aa7c3c81291cad52dd70aec947 100644 --- a/api/client.go +++ b/api/client.go @@ -205,11 +205,14 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie //Open the client c, err := OpenClient(storageDir, password, parameters) - if err != nil { return nil, err } + u := c.storage.GetUser() + jww.INFO.Printf("Client Logged in: \n\tTransmisstionID: %s " + + "\n\tReceptionID: %s", u.TransmissionID, u.ReceptionID) + //Attach the services interface c.services = newServiceProcessiesList(c.runner) @@ -388,7 +391,9 @@ func (c *Client) initPermissioning(def *ndf.NetworkDefinition) error { // - Auth Callback (/auth/callback.go) // Handles both auth confirm and requests func (c *Client) StartNetworkFollower() (<-chan interfaces.ClientError, error) { - jww.INFO.Printf("StartNetworkFollower()") + u := c.GetUser() + jww.INFO.Printf("StartNetworkFollower() \n\tTransmisstionID: %s " + + "\n\tReceptionID: %s", u.TransmissionID, u.ReceptionID) c.clientErrorChannel = make(chan interfaces.ClientError, 1000) diff --git a/bindings/client.go b/bindings/client.go index 2ebc43897cf4daa64f420a1831167cd746ff22b8..391aa361c6da731a19d2647d6d3aacd003e70208 100644 --- a/bindings/client.go +++ b/bindings/client.go @@ -36,7 +36,6 @@ func init() { // to support the gomobile Client interface type Client struct { api api.Client - waitForNetwork chan bool } // NewClient creates client storage, generates keys, connects, and registers @@ -225,41 +224,15 @@ func (c *Client) StopNetworkFollower(timeoutMS int) error { // WaitForNewtwork will block until either the network is healthy or the // passed timeout. It will return true if the network is healthy func (c *Client) WaitForNetwork(timeoutMS int) bool { - timeout := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond) - if c.waitForNetwork == nil{ - c.waitForNetwork = make(chan bool, 1) - c.api.GetHealth().AddChannel(c.waitForNetwork) - } - - //flush the channel if it is already full - select{ - case <- c.waitForNetwork: - default: - } - - // start a thread to check if healthy in a second in order to handle - // race conditions - go func() { - time.Sleep(1*time.Second) - if c.api.GetHealth().IsHealthy() { - select{ - case c.waitForNetwork<-true: - default: - } - } - }() - - //wait for network to be healthy or the timer to time out - for { - select{ - case result := <- c.waitForNetwork: - if result { - return true - } - case <-timeout.C: - return false + start := time.Now() + timeout := time.Duration(timeoutMS)*time.Millisecond + for time.Now().Sub(start)<timeout{ + if c.api.GetHealth().IsHealthy(){ + return true } + time.Sleep(250*time.Millisecond) } + return false } // Gets the state of the network follower. Returns: diff --git a/network/follow.go b/network/follow.go index 6775ef7ea0c49d58e3a9bbd6b96ae7ebf3856d7a..752476ea1e7b821d942ca88d3b36dba19d87c5a0 100644 --- a/network/follow.go +++ b/network/follow.go @@ -262,7 +262,7 @@ func (m *manager) follow(report interfaces.ClientErrorReport, rng csprng.Source, _, changed := identity.ER.Set(earliestRemaining) if changed{ jww.TRACE.Printf("External returns of RangeUnchecked: %d, %v, %v", earliestRemaining, roundsWithMessages, roundsUnknown) - jww.INFO.Printf("New Earliest Remaining: %d", earliestRemaining) + jww.DEBUG.Printf("New Earliest Remaining: %d", earliestRemaining) } roundsWithMessages2 := identity.UR.Iterate(func(rid id.Round)bool{ diff --git a/network/health/tracker.go b/network/health/tracker.go index 7779a86b96502c2d34a17690e26c79c46bcdad8b..ff53904f2015fe81af4938efd9ca8222fd68eba1 100644 --- a/network/health/tracker.go +++ b/network/health/tracker.go @@ -159,7 +159,7 @@ func (t *Tracker) transmit(health bool) { select { case c <- health: default: - jww.WARN.Printf("Unable to send Health event") + jww.DEBUG.Printf("Unable to send Health event") } } diff --git a/storage/e2e/manager.go b/storage/e2e/manager.go index b1feb294761730105b5fa70fa9f27b669c79f78a..802e81ebe2329f5bd3714500e0229071eaea3bd3 100644 --- a/storage/e2e/manager.go +++ b/storage/e2e/manager.go @@ -159,8 +159,7 @@ func (m *Manager) GetKeyForSending(st params.SendType) (*Key, error) { // GetPartnerID returns a copy of the ID of the partner. func (m *Manager) GetPartnerID() *id.ID { - p := m.partner - return p + return m.partner.DeepCopy() } // GetSendSession gets the Send session of the passed ID. Returns nil if no diff --git a/storage/e2e/session.go b/storage/e2e/session.go index b51c0584780b60d28ced2004ce48159495b929be..5f0344378ae7f106edd4c447904dd89cb2b6ca94 100644 --- a/storage/e2e/session.go +++ b/storage/e2e/session.go @@ -37,6 +37,8 @@ type Session struct { //params e2eParams params.E2ESessionParams + partner *id.ID + //type t RelationshipType @@ -92,6 +94,8 @@ type SessionDisk struct { // Number of keys usable before rekey RekeyThreshold uint32 + + Partner []byte } /*CONSTRUCTORS*/ @@ -115,6 +119,7 @@ func newSession(ship *relationship, t RelationshipType, myPrivKey, partnerPubKey relationshipFingerprint: relationshipFingerprint, negotiationStatus: negotiationStatus, partnerSource: trigger, + partner: ship.manager.partner.DeepCopy(), } session.kv = session.generate(ship.kv) @@ -168,6 +173,11 @@ func loadSession(ship *relationship, kv *versioned.KV, } session.relationshipFingerprint = relationshipFingerprint + if !session.partner.Cmp(ship.manager.partner){ + return nil, errors.Errorf("Stored partner (%s) did not match " + + "relationship partner (%s)", session.partner, ship.manager.partner) + } + return &session, nil } @@ -262,7 +272,7 @@ func (s *Session) GetID() SessionID { // returns the ID of the partner for this session func (s *Session) GetPartner() *id.ID { if s.relationship != nil { - return s.relationship.manager.partner + return s.relationship.manager.partner.DeepCopy() } else { return nil } @@ -279,6 +289,7 @@ func (s *Session) marshal() ([]byte, error) { sd.PartnerPubKey = s.partnerPubKey.Bytes() sd.Trigger = s.partnerSource[:] sd.RelationshipFingerprint = s.relationshipFingerprint + sd.Partner = s.partner.Bytes() // assume in progress confirmations and session creations have failed on // reset, therefore do not store their pending progress @@ -315,6 +326,7 @@ func (s *Session) unmarshal(b []byte) error { s.negotiationStatus = Negotiation(sd.Confirmation) s.rekeyThreshold = sd.RekeyThreshold s.relationshipFingerprint = sd.RelationshipFingerprint + s.partner, _ = id.Unmarshal(sd.Partner) copy(s.partnerSource[:], sd.Trigger) s.keyState, err = loadStateVector(s.kv, "") diff --git a/storage/e2e/session_test.go b/storage/e2e/session_test.go index 1043dc556d928c61984fc6af3de00759e9b1e174..800cac5410e8b5236d9c89aa5ed90c36a49bc654 100644 --- a/storage/e2e/session_test.go +++ b/storage/e2e/session_test.go @@ -630,6 +630,7 @@ func makeTestSession() (*Session, *context) { manager: &Manager{ ctx: ctx, kv: kv, + partner: &id.ID{}, }, kv: kv, }, @@ -637,6 +638,7 @@ func makeTestSession() (*Session, *context) { t: Receive, negotiationStatus: Confirmed, rekeyThreshold: 5, + partner: &id.ID{}, } var err error s.keyState, err = newStateVector(s.kv, diff --git a/storage/e2e/store.go b/storage/e2e/store.go index 001f077e826d3e1e3f3627cbf500dfae926a3b1a..2065bda640e36831b60f24a4dbbd7742f7513db7 100644 --- a/storage/e2e/store.go +++ b/storage/e2e/store.go @@ -258,6 +258,12 @@ func (s *Store) unmarshal(b []byte) error { &partnerID, err.Error()) } + if !manager.GetPartnerID().Cmp(&partnerID){ + jww.FATAL.Panicf("Loaded a manager with the wrong partner " + + "ID: \n\t loaded: %s \n\t present: %s", + &partnerID, manager.GetPartnerID()) + } + s.managers[partnerID] = manager }