-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PeerList][Part 5] SinglePeerList #403
Conversation
67423a5
to
9dd824b
Compare
6d416e7
to
2b4961f
Compare
|
||
type single struct { | ||
peerID transport.PeerIdentifier | ||
peer transport.Peer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to assume that peerID is irrelevant once peer is set? Maybe mention that in a comment?
} | ||
|
||
// NotifyPending when the number of Pending requests changes | ||
func (pl *single) NotifyStatusChanged(transport.Peer) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outdated comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping
9dd824b
to
fb2b309
Compare
ab9c17f
to
8c22b83
Compare
|
||
func (pl *single) Start() error { | ||
if pl.started.Swap(true) { | ||
return errors.ErrPeerListAlreadyStarted("single") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to use a RW Mutex instead. There's a race here where if I
call Start
and ChoosePeer
concurrently, started
is set to true by
Start
but ChoosePeer
returns the nil
peer before Start
has a chance to
fill it in.
} | ||
|
||
// NotifyPending when the number of Pending requests changes | ||
func (pl *single) NotifyStatusChanged(transport.Peer) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping
s.expectedPeerID = s.pid | ||
s.expectedAgent = s.agent | ||
s.expectedStarted = false | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of combining all these tests, it's okay (preferable even) to split
tests for different behaviors out into different test functions. Table tests
are for tests with enough similar structure that writing those into separate
functions would be redundant. As it stands right now, it's very difficult to
figure out what each of these tests is actually testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fb2b309
to
46e41f9
Compare
8c22b83
to
a8ab052
Compare
} | ||
|
||
// NewSingle creates a static PeerList with a single Peer | ||
func NewSingle(pi transport.PeerIdentifier, agent transport.Agent) transport.PeerList { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consistency! pid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
for _, tt := range tests { | ||
pl := NewSingle(tt.pid, tt.agent).(*single) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subtests :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil | ||
} | ||
|
||
func (pl *single) ChoosePeer(context.Context, *transport.Request) (transport.Peer, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do I understand that every new request will call this function first locking the mutex on the way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a read lock yes, for this list it doesn't make as much sense, but once we start adding/removing peers I think it will be a good idea, or at least we'll need to be explicitly aware when we remove the mutexes (for performance reasons).
46e41f9
to
47539ec
Compare
a8ab052
to
04165b8
Compare
47539ec
to
a393d95
Compare
04165b8
to
99078d1
Compare
a393d95
to
4b3ef1f
Compare
99078d1
to
91af1f5
Compare
91af1f5
to
955c76f
Compare
Summary: This PR creates a concrete peerlist implementation that has a single peer implementation.
955c76f
to
e3c5ff2
Compare
Summary: This PR creates a concrete peerlist implementation that has a single peer implementation. This can be used to shim the current existing http outbounds and replace them with a single PeerList
Summary: This PR creates a concrete peerlist implementation that has a single peer implementation. This can be used to shim the current existing http outbounds and replace them with a single PeerList
Summary: This PR creates a concrete peerlist implementation that has a
single peer implementation.