Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
x0x
dht
Commits
8cfd0386
Commit
8cfd0386
authored
Nov 06, 2019
by
Matt Joiner
Browse files
Use atomic for Announce.numContacted
parent
e40f4bee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
announce.go
announce.go
+5
-5
No files found.
announce.go
View file @
8cfd0386
...
...
@@ -5,6 +5,7 @@ package dht
import
(
"context"
"net"
"sync/atomic"
"github.com/anacrolix/missinggo/v2/conntrack"
"github.com/anacrolix/stm"
...
...
@@ -30,7 +31,7 @@ type Announce struct {
server
*
Server
infoHash
int160
// Target
// Count of (probably) distinct addresses we've sent get_peers requests to.
numContacted
*
stm
.
Var
//
int
numContacted
int
64
// The torrent port that we're announcing.
announcePort
int
// The torrent port should be determined by the receiver in case we're
...
...
@@ -48,8 +49,8 @@ type pendingAnnouncePeer struct {
}
// Returns the number of distinct remote addresses the announce has queried.
func
(
a
*
Announce
)
NumContacted
()
int
{
return
stm
.
AtomicGet
(
a
.
numContacted
)
.
(
int
)
func
(
a
*
Announce
)
NumContacted
()
int
64
{
return
atomic
.
LoadInt64
(
&
a
.
numContacted
)
}
// Traverses the DHT graph toward nodes that store peers for the infohash, streaming them to the
...
...
@@ -69,7 +70,6 @@ func (s *Server) Announce(infoHash [20]byte, port int, impliedPort bool) (*Annou
announcePort
:
port
,
announcePortImplied
:
impliedPort
,
pending
:
stm
.
NewVar
(
0
),
numContacted
:
stm
.
NewVar
(
0
),
pendingAnnouncePeers
:
stm
.
NewVar
(
immutable
.
NewList
()),
traversal
:
newTraversal
(
infoHashInt160
),
}
...
...
@@ -260,8 +260,8 @@ func (a *Announce) nodeContactor() {
func
(
a
*
Announce
)
beginGetPeers
(
tx
*
stm
.
Tx
)
interface
{}
{
addr
:=
a
.
traversal
.
nextAddr
(
tx
)
dhtAddr
:=
NewAddr
(
addr
.
UDP
())
tx
.
Set
(
a
.
numContacted
,
tx
.
Get
(
a
.
numContacted
)
.
(
int
)
+
1
)
return
a
.
beginQuery
(
dhtAddr
,
"dht announce get_peers"
,
func
()
numWrites
{
atomic
.
AddInt64
(
&
a
.
numContacted
,
1
)
return
a
.
getPeers
(
dhtAddr
)
})(
tx
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment