-
Notifications
You must be signed in to change notification settings - Fork 108
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
HTTP retrieval proposal #747
base: main
Are you sure you want to change the base?
Changes from all commits
ca858e9
65789d1
f9906e6
54b1dbe
016a7e5
65d948d
c6a1b06
fff0d66
db62ab3
cecbd99
bad15ee
be0679c
bc9830e
1a08034
96bdb9d
0c08659
9b23ecf
5270ba2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package bsnet | ||
|
||
import "github.com/ipfs/boxo/bitswap/network/bsnet/internal" | ||
|
||
var ( | ||
// ProtocolBitswapNoVers is equivalent to the legacy bitswap protocol | ||
ProtocolBitswapNoVers = internal.ProtocolBitswapNoVers | ||
// ProtocolBitswapOneZero is the prefix for the legacy bitswap protocol | ||
ProtocolBitswapOneZero = internal.ProtocolBitswapOneZero | ||
// ProtocolBitswapOneOne is the prefix for version 1.1.0 | ||
ProtocolBitswapOneOne = internal.ProtocolBitswapOneOne | ||
// ProtocolBitswap is the current version of the bitswap protocol: 1.2.0 | ||
ProtocolBitswap = internal.ProtocolBitswap | ||
) | ||
Comment on lines
+1
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved from |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package network | ||
package bsnet | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes to this file and others in the module are cosmetic, renames... |
||
import ( | ||
"context" | ||
|
@@ -9,10 +9,10 @@ import ( | |
"time" | ||
|
||
bsmsg "github.com/ipfs/boxo/bitswap/message" | ||
"github.com/ipfs/boxo/bitswap/network/internal" | ||
iface "github.com/ipfs/boxo/bitswap/network" | ||
"github.com/ipfs/boxo/bitswap/network/bsnet/internal" | ||
|
||
logging "github.com/ipfs/go-log/v2" | ||
"github.com/libp2p/go-libp2p/core/connmgr" | ||
"github.com/libp2p/go-libp2p/core/host" | ||
"github.com/libp2p/go-libp2p/core/network" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
|
@@ -23,7 +23,7 @@ import ( | |
"github.com/multiformats/go-multistream" | ||
) | ||
|
||
var log = logging.Logger("bitswap/network") | ||
var log = logging.Logger("bitswap/bsnet") | ||
|
||
var ( | ||
maxSendTimeout = 2 * time.Minute | ||
|
@@ -33,7 +33,7 @@ var ( | |
) | ||
|
||
// NewFromIpfsHost returns a BitSwapNetwork supported by underlying IPFS host. | ||
func NewFromIpfsHost(host host.Host, opts ...NetOpt) BitSwapNetwork { | ||
func NewFromIpfsHost(host host.Host, opts ...NetOpt) iface.BitSwapNetwork { | ||
s := processSettings(opts...) | ||
|
||
bitswapNetwork := impl{ | ||
|
@@ -66,10 +66,10 @@ func processSettings(opts ...NetOpt) Settings { | |
type impl struct { | ||
// NOTE: Stats must be at the top of the heap allocation to ensure 64bit | ||
// alignment. | ||
stats Stats | ||
stats iface.Stats | ||
|
||
host host.Host | ||
connectEvtMgr *connectEventManager | ||
connectEvtMgr *iface.ConnectEventManager | ||
|
||
protocolBitswapNoVers protocol.ID | ||
protocolBitswapOneZero protocol.ID | ||
|
@@ -79,7 +79,7 @@ type impl struct { | |
supportedProtocols []protocol.ID | ||
|
||
// inbound messages from the network are forwarded to the receiver | ||
receivers []Receiver | ||
receivers []iface.Receiver | ||
} | ||
|
||
// interfaceWrapper is concrete type that wraps an interface. Necessary because | ||
|
@@ -109,7 +109,7 @@ type streamMessageSender struct { | |
to peer.ID | ||
stream atomicInterface[network.Stream] | ||
bsnet *impl | ||
opts *MessageSenderOpts | ||
opts *iface.MessageSenderOpts | ||
} | ||
|
||
type HasContext interface { | ||
|
@@ -317,7 +317,7 @@ func (bsnet *impl) msgToStream(ctx context.Context, s network.Stream, msg bsmsg. | |
return nil | ||
} | ||
|
||
func (bsnet *impl) NewMessageSender(ctx context.Context, p peer.ID, opts *MessageSenderOpts) (MessageSender, error) { | ||
func (bsnet *impl) NewMessageSender(ctx context.Context, p peer.ID, opts *iface.MessageSenderOpts) (iface.MessageSender, error) { | ||
opts = setDefaultOpts(opts) | ||
|
||
sender := &streamMessageSender{ | ||
|
@@ -337,7 +337,7 @@ func (bsnet *impl) NewMessageSender(ctx context.Context, p peer.ID, opts *Messag | |
return sender, nil | ||
} | ||
|
||
func setDefaultOpts(opts *MessageSenderOpts) *MessageSenderOpts { | ||
func setDefaultOpts(opts *iface.MessageSenderOpts) *iface.MessageSenderOpts { | ||
copy := *opts | ||
if opts.MaxRetries == 0 { | ||
copy.MaxRetries = 3 | ||
|
@@ -385,14 +385,14 @@ func (bsnet *impl) newStreamToPeer(ctx context.Context, p peer.ID) (network.Stre | |
return bsnet.host.NewStream(ctx, p, bsnet.supportedProtocols...) | ||
} | ||
|
||
func (bsnet *impl) Start(r ...Receiver) { | ||
func (bsnet *impl) Start(r ...iface.Receiver) { | ||
bsnet.receivers = r | ||
{ | ||
connectionListeners := make([]ConnectionListener, len(r)) | ||
connectionListeners := make([]iface.ConnectionListener, len(r)) | ||
for i, v := range r { | ||
connectionListeners[i] = v | ||
} | ||
bsnet.connectEvtMgr = newConnectEventManager(connectionListeners...) | ||
bsnet.connectEvtMgr = iface.NewConnectEventManager(connectionListeners...) | ||
} | ||
for _, proto := range bsnet.supportedProtocols { | ||
bsnet.host.SetStreamHandler(proto, bsnet.handleNewStream) | ||
|
@@ -451,12 +451,36 @@ func (bsnet *impl) handleNewStream(s network.Stream) { | |
} | ||
} | ||
|
||
func (bsnet *impl) ConnectionManager() connmgr.ConnManager { | ||
return bsnet.host.ConnManager() | ||
func (bsnet *impl) TagPeer(p peer.ID, tag string, w int) { | ||
if bsnet.host == nil { | ||
return | ||
} | ||
bsnet.host.ConnManager().TagPeer(p, tag, w) | ||
} | ||
|
||
func (bsnet *impl) UntagPeer(p peer.ID, tag string) { | ||
if bsnet.host == nil { | ||
return | ||
} | ||
bsnet.host.ConnManager().UntagPeer(p, tag) | ||
} | ||
|
||
func (bsnet *impl) Protect(p peer.ID, tag string) { | ||
if bsnet.host == nil { | ||
return | ||
} | ||
bsnet.host.ConnManager().Protect(p, tag) | ||
} | ||
|
||
func (bsnet *impl) Unprotect(p peer.ID, tag string) bool { | ||
if bsnet.host == nil { | ||
return false | ||
} | ||
return bsnet.host.ConnManager().Unprotect(p, tag) | ||
} | ||
|
||
func (bsnet *impl) Stats() Stats { | ||
return Stats{ | ||
func (bsnet *impl) Stats() iface.Stats { | ||
return iface.Stats{ | ||
MessagesRecvd: atomic.LoadUint64(&bsnet.stats.MessagesRecvd), | ||
MessagesSent: atomic.LoadUint64(&bsnet.stats.MessagesSent), | ||
} | ||
|
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.
Turns out, peer ID is not used in the peermanager.