Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahhoward committed Jan 26, 2019
1 parent f8ad5f2 commit 546ad70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package session

import (
"context"
"fmt"
"time"

lru "github.com/hashicorp/golang-lru"
Expand Down Expand Up @@ -246,6 +247,7 @@ func (s *Session) run(ctx context.Context) {
case keys := <-s.cancelKeys:
s.handleCancel(keys)
case <-s.tick.C:
fmt.Println("TICK!")
s.handleTick(ctx)
case lwchk := <-s.interestReqs:
lwchk.resp <- s.cidIsWanted(lwchk.c)
Expand Down Expand Up @@ -308,6 +310,7 @@ func (s *Session) handleTick(ctx context.Context) {

// Broadcast these keys to everyone we're connected to
s.pm.RecordPeerRequests(nil, live)
fmt.Println("Broadcast!")
s.wm.WantBlocks(ctx, live, nil, s.id)

if len(live) > 0 {
Expand Down Expand Up @@ -382,10 +385,12 @@ func (s *Session) wantBlocks(ctx context.Context, ks []cid.Cid) {
splitRequests := s.srs.SplitRequest(peers, ks)
for _, splitRequest := range splitRequests {
s.pm.RecordPeerRequests(splitRequest.Peers, splitRequest.Keys)
fmt.Println("Target!")
s.wm.WantBlocks(ctx, splitRequest.Keys, splitRequest.Peers, s.id)
}
} else {
s.pm.RecordPeerRequests(nil, ks)
fmt.Println("Broadcast!")
s.wm.WantBlocks(ctx, ks, nil, s.id)
}
}
Expand All @@ -399,6 +404,10 @@ func (s *Session) resetTick() {
s.tick.Reset(provSearchDelay)
} else {
avLat := s.averageLatency()
fmt.Printf("Base Tick Delay: %f seconds\n", s.baseTickDelay.Seconds())
fmt.Printf("Average Latency: %f seconds\n", avLat.Seconds())
fmt.Printf("Total Tick Delay: %f seconds\n", (s.baseTickDelay + (3 * avLat)).Seconds())

s.tick.Reset(s.baseTickDelay + (3 * avLat))
}
}
Expand Down
3 changes: 2 additions & 1 deletion session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestSessionGetBlocks(t *testing.T) {

func TestSessionFindMorePeers(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
wantReqs := make(chan wantReq, 1)
cancelReqs := make(chan wantReq, 1)
Expand Down Expand Up @@ -227,6 +227,7 @@ func TestSessionFindMorePeers(t *testing.T) {
select {
case <-getBlocksCh:
case <-ctx.Done():
t.Fatal("Did not get block back")
}
select {
case <-wantReqs:
Expand Down

0 comments on commit 546ad70

Please sign in to comment.