diff --git a/network/historical/historical.go b/network/historical/historical.go index 5ed89c1cd4708aa877d53bc51f9cb04bea2be25f..f21a5e711b3c675edb893e6dfda9731a52cced59 100644 --- a/network/historical/historical.go +++ b/network/historical/historical.go @@ -53,7 +53,7 @@ type RoundsComms interface { } // RoundResultCallback is the used callback when a round is found. -type RoundResultCallback func(info Round, success bool) +type RoundResultCallback func(round Round, success bool) // roundRequest is an internal structure that tracks a request. type roundRequest struct { diff --git a/network/historical/historical_test.go b/network/historical/historical_test.go index 7c30c8fe9da408ae1b66c48b1f19f7b281266a46..af3ef9d9dd44ae1d5de64c3d38ce327e6f13ac73 100644 --- a/network/historical/historical_test.go +++ b/network/historical/historical_test.go @@ -84,8 +84,8 @@ func Test_processHistoricalRoundsResponse(t *testing.T) { } expiredRR := roundRequest{ rid: id.Round(42), - RoundResultCallback: func(info Round, success bool) { - if info.ID == 0 && !success { + RoundResultCallback: func(round Round, success bool) { + if round.ID == 0 && !success { return } t.Errorf("Expired called with bad params.") @@ -108,12 +108,15 @@ func Test_processHistoricalRoundsResponse(t *testing.T) { infos := make([]*pb.RoundInfo, 3) infos[0] = nil infos[1] = nil - infos[2] = &pb.RoundInfo{ID: 43} + infos[2] = &pb.RoundInfo{ + ID: 43, + Topology: [][]byte{{1}, {2}}, + } response := &pb.HistoricalRoundsResponse{Rounds: infos} events := &testEventMgr{} - rids, retries := processHistoricalRoundsResponse(response, rrs, - params.MaxHistoricalRoundsRetries, events) + rids, retries := processHistoricalRoundsResponse( + response, rrs, params.MaxHistoricalRoundsRetries, events) if len(rids) != 1 || rids[0] != 43 { t.Errorf("Bad return: %v, expected [43]", rids) diff --git a/network/historical/round.go b/network/historical/round.go index 6e809ad4709c36343df2041cb5ed158301a998cf..5dac9bec59a62c99ab9059b68fc86ed07f1a4aec 100644 --- a/network/historical/round.go +++ b/network/historical/round.go @@ -10,10 +10,10 @@ import ( ) type Round struct { - //ID of the round. Ids are sequential and monotonic + // ID of the round. IDs are sequential and monotonic. ID id.Round - // Last known state of the round. Possible states are: + // State is the last known state of the round. Possible states are: // PENDING - not started yet // PRECOMPUTING - In the process of preparing to process messages // STANDBY - Completed precomputing but not yet scheduled to run @@ -23,32 +23,32 @@ type Round struct { // FAILED - Failed to deliver messages State states.Round - // List of Nodes in the round + // Topology contains the list of nodes in the round. Topology *connect.Circuit - // Timestamps of all events that have occurred in the round - // (See the above states). - // The Queued state's timestamp is different, it denotes when Realtime - // was/is scheduled to start, not whe the Queued state is entered + // Timestamps of all events that have occurred in the round (see the above + // states). + // The QUEUED state's timestamp is different; it denotes when Realtime + // was/is scheduled to start, not whe the QUEUED state is entered. Timestamps map[states.Round]time.Time // Errors that occurred in the round. Will only be present in the failed - // state + // state. Errors []RoundError - /*Properties*/ + /* Properties */ - // Max number of messages the round can process + // BatchSize is the max number of messages the round can process. BatchSize uint32 - // Ephemeral Address space size used in the round + // AddressSpaceSize is the ephemeral address space size used in the round. AddressSpaceSize uint8 - // Monotonic counter between all round updates denoting when this updated - //occurred in the queue + // UpdateID is a monotonic counter between all round updates denoting when + // this updated occurred in the queue. UpdateID uint64 - // RawData round data, including signatures + // Raw is raw round data, including signatures. Raw *pb.RoundInfo } @@ -57,9 +57,9 @@ type RoundError struct { Error string } -//MakeRound Builds an accessable round object from a RoundInfo Protobuff +// MakeRound builds an accessible round object from a RoundInfo protobuf. func MakeRound(ri *pb.RoundInfo) Round { - //Build the timestamps map + // Build the timestamps map timestamps := make(map[states.Round]time.Time) for i := range ri.Timestamps { @@ -69,7 +69,7 @@ func MakeRound(ri *pb.RoundInfo) Round { } } - //Build the input to the topology + // Build the input to the topology nodes := make([]*id.ID, len(ri.Topology)) for i := range ri.Topology { newNodeID := id.ID{} @@ -77,7 +77,7 @@ func MakeRound(ri *pb.RoundInfo) Round { nodes[i] = &newNodeID } - //build the errors + // Build the errors errs := make([]RoundError, len(ri.Errors)) for i := range ri.Errors { errNodeID := id.ID{} @@ -101,8 +101,8 @@ func MakeRound(ri *pb.RoundInfo) Round { } } -// GetEndTimestamp Returns the timestamp of the last known event, -// which is generally the state unless in queued, which stores the next event +// GetEndTimestamp returns the timestamp of the last known event, which is +// generally the state unless in queued, which stores the next event. func (r Round) GetEndTimestamp() time.Time { switch r.State { case states.PENDING: @@ -121,6 +121,7 @@ func (r Round) GetEndTimestamp() time.Time { jww.FATAL.Panicf("Could not get final timestamp of round, "+ "invalid state: %s", r.State) } - //unreachable + + // Unreachable return time.Time{} } diff --git a/network/message/inProgress_test.go b/network/message/inProgress_test.go index f76d9c760094ccb0b80ab394fe59928041a810e4..919090cee3c15c456d6364aed0b3eb9783b5a720 100644 --- a/network/message/inProgress_test.go +++ b/network/message/inProgress_test.go @@ -39,7 +39,8 @@ func TestHandler_CheckInProgressMessages(t *testing.T) { t.Errorf("Failed to add fingerprint: %+v", err) } h.inProcess.Add(msg, - &pb.RoundInfo{ID: 1, Timestamps: []uint64{0, 1, 2, 3}}, + &pb.RoundInfo{ID: 1, Timestamps: []uint64{0, 1, 2, 3}, + Topology: [][]byte{{1}, {2}}}, receptionID.EphemeralIdentity{Source: cid}) stop := stoppable.NewSingle("stop") diff --git a/network/rounds/get.go b/network/rounds/get.go index 18cf8d60c8e923d0435972090b11015f7e5bb956..2954bb69e6ebba6e1a6529a6562f73c0d213855d 100644 --- a/network/rounds/get.go +++ b/network/rounds/get.go @@ -41,14 +41,14 @@ func (m *manager) GetMessagesFromRound( identity.Source) err = m.historical.LookupHistoricalRound( - roundID, func(info historical.Round, success bool) { + roundID, func(round historical.Round, success bool) { if !success { // TODO: Implement me } // If found, send to Message Retrieval Workers m.lookupRoundMessages <- roundLookup{ - Round: info, + Round: round, Identity: identity, } }) diff --git a/network/rounds/retrieve_test.go b/network/rounds/retrieve_test.go index 02fc5397020951a8677e336bfeff17df0f4f8b73..c303d71c4c36c6c5f10efa7f2757b72f10c69312 100644 --- a/network/rounds/retrieve_test.go +++ b/network/rounds/retrieve_test.go @@ -71,14 +71,14 @@ func Test_manager_processMessageRetrieval(t *testing.T) { Source: requestGateway, } - roundInfo := historical.Round{ + round := historical.Round{ ID: roundId, Topology: connect.NewCircuit([]*id.ID{requestGateway}), } // Send a round look up request testManager.lookupRoundMessages <- roundLookup{ - Round: roundInfo, + Round: round, Identity: ephIdentity, } @@ -159,14 +159,14 @@ func Test_manager_processMessageRetrieval_NoRound(t *testing.T) { Source: dummyGateway, } - roundInfo := historical.Round{ + round := historical.Round{ ID: roundId, Topology: connect.NewCircuit([]*id.ID{dummyGateway}), } // Send a round look up request testManager.lookupRoundMessages <- roundLookup{ - Round: roundInfo, + Round: round, Identity: identity, } @@ -236,14 +236,14 @@ func Test_manager_processMessageRetrieval_FalsePositive(t *testing.T) { requestGateway := id.NewIdFromString(FalsePositive, id.Gateway, t) - roundInfo := historical.Round{ + round := historical.Round{ ID: roundId, Topology: connect.NewCircuit([]*id.ID{requestGateway}), } // Send a round look up request testManager.lookupRoundMessages <- roundLookup{ - Round: roundInfo, + Round: round, Identity: identity, } @@ -309,13 +309,13 @@ func Test_manager_processMessageRetrieval_Quit(t *testing.T) { requestGateway := id.NewIdFromString(ReturningGateway, id.Gateway, t) - roundInfo := historical.Round{ + round := historical.Round{ ID: roundId, Topology: connect.NewCircuit([]*id.ID{requestGateway}), } // Send a round look up request testManager.lookupRoundMessages <- roundLookup{ - Round: roundInfo, + Round: round, Identity: identity, } @@ -353,9 +353,8 @@ func Test_manager_processMessageRetrieval_MultipleGateways(t *testing.T) { p := gateway.DefaultPoolParams() p.MaxPoolSize = 1 - testManager.sender, _ = gateway.NewSender(p, - testManager.rng, - testNdf, mockComms, testManager.session, nil) + testManager.sender, _ = gateway.NewSender( + p, testManager.rng, testNdf, mockComms, testManager.session, nil) // Create a local channel so reception is possible // (testManager.messageBundles is sent only via newManager call above) @@ -380,17 +379,17 @@ func Test_manager_processMessageRetrieval_MultipleGateways(t *testing.T) { Source: requestGateway, } - roundInfo := historical.Round{ + round := historical.Round{ ID: roundId, // Create a list of IDs in which some error gateways must be // contacted before the happy path - Topology: connect.NewCircuit([]*id.ID{errorGateway, errorGateway, - requestGateway}), + Topology: connect.NewCircuit( + []*id.ID{errorGateway, requestGateway}), } // Send a round look up request testManager.lookupRoundMessages <- roundLookup{ - Round: roundInfo, + Round: round, Identity: identity, }