Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
f60995ea
Commit
f60995ea
authored
Oct 14, 2017
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag peers associated with a bitswap session
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
8c2a566e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
2 deletions
+28
-2
network/interface.go
network/interface.go
+4
-0
network/ipfs_impl.go
network/ipfs_impl.go
+5
-0
session.go
session.go
+13
-1
testnet/virtual.go
testnet/virtual.go
+6
-1
No files found.
network/interface.go
View file @
f60995ea
...
...
@@ -4,8 +4,10 @@ import (
"context"
bsmsg
"github.com/ipfs/go-ipfs/exchange/bitswap/message"
cid
"gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
peer
"gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
ifconnmgr
"gx/ipfs/QmYkCrTwivapqdB3JbwvwvxymseahVkcm46ThRMAA24zCr/go-libp2p-interface-connmgr"
protocol
"gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
)
...
...
@@ -34,6 +36,8 @@ type BitSwapNetwork interface {
NewMessageSender
(
context
.
Context
,
peer
.
ID
)
(
MessageSender
,
error
)
ConnectionManager
()
ifconnmgr
.
ConnManager
Routing
}
...
...
network/ipfs_impl.go
View file @
f60995ea
...
...
@@ -15,6 +15,7 @@ import (
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
ma
"gx/ipfs/QmXY77cVe7rVRQXZZQRioukUM7aRW3BTcAgJe12MCtb3Ji/go-multiaddr"
peer
"gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
ifconnmgr
"gx/ipfs/QmYkCrTwivapqdB3JbwvwvxymseahVkcm46ThRMAA24zCr/go-libp2p-interface-connmgr"
ggio
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io"
host
"gx/ipfs/Qmc1XhrFEiSeBNn3mpfg6gEuYCt5im2gYmNVmncsvmpeAk/go-libp2p-host"
)
...
...
@@ -212,6 +213,10 @@ func (bsnet *impl) handleNewStream(s inet.Stream) {
}
}
func
(
bsnet
*
impl
)
ConnectionManager
()
ifconnmgr
.
ConnManager
{
return
bsnet
.
host
.
ConnManager
()
}
type
netNotifiee
impl
func
(
nn
*
netNotifiee
)
impl
()
*
impl
{
...
...
session.go
View file @
f60995ea
...
...
@@ -2,6 +2,7 @@ package bitswap
import
(
"context"
"fmt"
"time"
notifications
"github.com/ipfs/go-ipfs/exchange/bitswap/notifications"
...
...
@@ -44,7 +45,8 @@ type Session struct {
uuid
logging
.
Loggable
id
uint64
id
uint64
tag
string
}
// NewSession creates a new bitswap session whose lifetime is bounded by the
...
...
@@ -66,6 +68,8 @@ func (bs *Bitswap) NewSession(ctx context.Context) *Session {
id
:
bs
.
getNextSessionID
(),
}
s
.
tag
=
fmt
.
Sprint
(
"bs-ses-"
,
s
.
id
)
cache
,
_
:=
lru
.
New
(
2048
)
s
.
interest
=
cache
...
...
@@ -139,6 +143,9 @@ func (s *Session) addActivePeer(p peer.ID) {
if
_
,
ok
:=
s
.
activePeers
[
p
];
!
ok
{
s
.
activePeers
[
p
]
=
struct
{}{}
s
.
activePeersArr
=
append
(
s
.
activePeersArr
,
p
)
cmgr
:=
s
.
bs
.
network
.
ConnectionManager
()
cmgr
.
TagPeer
(
p
,
s
.
tag
,
10
)
}
}
...
...
@@ -216,6 +223,11 @@ func (s *Session) run(ctx context.Context) {
case
<-
ctx
.
Done
()
:
s
.
tick
.
Stop
()
s
.
bs
.
removeSession
(
s
)
cmgr
:=
s
.
bs
.
network
.
ConnectionManager
()
for
_
,
p
:=
range
s
.
activePeersArr
{
cmgr
.
UntagPeer
(
p
,
s
.
tag
)
}
return
}
}
...
...
testnet/virtual.go
View file @
f60995ea
...
...
@@ -8,12 +8,13 @@ import (
bsnet
"github.com/ipfs/go-ipfs/exchange/bitswap/network"
mockrouting
"github.com/ipfs/go-ipfs/routing/mock"
delay
"github.com/ipfs/go-ipfs/thirdparty/delay"
testutil
"gx/ipfs/QmWRCn8vruNAzHx8i6SAXinuheRitKEGu8c7m26stKvsYx/go-testutil"
cid
"gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
routing
"gx/ipfs/QmPR2JzfKd9poHx9XBhzoFeBBC31ZM3W5iUPKJZWyaoZZm/go-libp2p-routing"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
testutil
"gx/ipfs/QmWRCn8vruNAzHx8i6SAXinuheRitKEGu8c7m26stKvsYx/go-testutil"
peer
"gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
ifconnmgr
"gx/ipfs/QmYkCrTwivapqdB3JbwvwvxymseahVkcm46ThRMAA24zCr/go-libp2p-interface-connmgr"
)
var
log
=
logging
.
Logger
(
"bstestnet"
)
...
...
@@ -118,6 +119,10 @@ func (nc *networkClient) FindProvidersAsync(ctx context.Context, k *cid.Cid, max
return
out
}
func
(
nc
*
networkClient
)
ConnectionManager
()
ifconnmgr
.
ConnManager
{
return
&
ifconnmgr
.
NullConnMgr
{}
}
type
messagePasser
struct
{
net
*
network
target
peer
.
ID
...
...
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