Skip to content

Commit 94fd3ac

Browse files
committed
chore: update boxo and internalize mplex
1 parent 2b7c20f commit 94fd3ac

File tree

21 files changed

+368
-183
lines changed

21 files changed

+368
-183
lines changed

config/bootstrap_peers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var DefaultBootstrapAddresses = []string{
1919
"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
2020
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
2121
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
22-
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
23-
"/ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
22+
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
23+
"/ip4/104.131.131.82/udp/4001/quic-v1/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
2424
}
2525

2626
// ErrInvalidPeerAddr signals an address is not a valid peer address.

config/init.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ func addressesConfig() Addresses {
114114
Swarm: []string{
115115
"/ip4/0.0.0.0/tcp/4001",
116116
"/ip6/::/tcp/4001",
117-
"/ip4/0.0.0.0/udp/4001/quic",
118117
"/ip4/0.0.0.0/udp/4001/quic-v1",
119118
"/ip4/0.0.0.0/udp/4001/quic-v1/webtransport",
120-
"/ip6/::/udp/4001/quic",
121119
"/ip6/::/udp/4001/quic-v1",
122120
"/ip6/::/udp/4001/quic-v1/webtransport",
123121
},

core/core_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ func TestInitialization(t *testing.T) {
2020
{
2121
Identity: id,
2222
Addresses: config.Addresses{
23-
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic"},
23+
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1"},
2424
API: []string{"/ip4/127.0.0.1/tcp/8000"},
2525
},
2626
},
2727

2828
{
2929
Identity: id,
3030
Addresses: config.Addresses{
31-
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic"},
31+
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1"},
3232
API: []string{"/ip4/127.0.0.1/tcp/8000"},
3333
},
3434
},

core/corehttp/metrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestPeersTotal(t *testing.T) {
4949
t.Fatalf("expected at most 2 peers transport (tcp and upd/quic), got %d, transport map %v",
5050
len(peersTransport), peersTransport)
5151
}
52-
totalPeers := peersTransport["/ip4/tcp"] + peersTransport["/ip4/udp/quic"]
52+
totalPeers := peersTransport["/ip4/tcp"] + peersTransport["/ip4/udp/quic-v1"]
5353
if totalPeers != 3 {
5454
t.Fatalf("expected 3 peers in either tcp or upd/quic transport, got %f", totalPeers)
5555
}

core/node/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
140140
}
141141

142142
c.Bootstrap = cfg.DefaultBootstrapAddresses
143-
c.Addresses.Swarm = []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic"}
143+
c.Addresses.Swarm = []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1"}
144144
c.Identity.PeerID = pid.Pretty()
145145
c.Identity.PrivKey = base64.StdEncoding.EncodeToString(privkeyb)
146146

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/conn.go
2+
package mplex
3+
4+
import (
5+
"context"
6+
7+
"github.com/libp2p/go-libp2p/core/network"
8+
9+
mp "github.com/libp2p/go-mplex"
10+
)
11+
12+
type conn mp.Multiplex
13+
14+
var _ network.MuxedConn = &conn{}
15+
16+
// NewMuxedConn constructs a new Conn from a *mp.Multiplex.
17+
func NewMuxedConn(m *mp.Multiplex) network.MuxedConn {
18+
return (*conn)(m)
19+
}
20+
21+
func (c *conn) Close() error {
22+
return c.mplex().Close()
23+
}
24+
25+
func (c *conn) IsClosed() bool {
26+
return c.mplex().IsClosed()
27+
}
28+
29+
// OpenStream creates a new stream.
30+
func (c *conn) OpenStream(ctx context.Context) (network.MuxedStream, error) {
31+
s, err := c.mplex().NewStream(ctx)
32+
if err != nil {
33+
return nil, err
34+
}
35+
return (*stream)(s), nil
36+
}
37+
38+
// AcceptStream accepts a stream opened by the other side.
39+
func (c *conn) AcceptStream() (network.MuxedStream, error) {
40+
s, err := c.mplex().Accept()
41+
if err != nil {
42+
return nil, err
43+
}
44+
return (*stream)(s), nil
45+
}
46+
47+
func (c *conn) mplex() *mp.Multiplex {
48+
return (*mp.Multiplex)(c)
49+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/stream.go
2+
package mplex
3+
4+
import (
5+
"time"
6+
7+
"github.com/libp2p/go-libp2p/core/network"
8+
9+
mp "github.com/libp2p/go-mplex"
10+
)
11+
12+
// stream implements network.MuxedStream over mplex.Stream.
13+
type stream mp.Stream
14+
15+
var _ network.MuxedStream = &stream{}
16+
17+
func (s *stream) Read(b []byte) (n int, err error) {
18+
n, err = s.mplex().Read(b)
19+
if err == mp.ErrStreamReset {
20+
err = network.ErrReset
21+
}
22+
23+
return n, err
24+
}
25+
26+
func (s *stream) Write(b []byte) (n int, err error) {
27+
n, err = s.mplex().Write(b)
28+
if err == mp.ErrStreamReset {
29+
err = network.ErrReset
30+
}
31+
32+
return n, err
33+
}
34+
35+
func (s *stream) Close() error {
36+
return s.mplex().Close()
37+
}
38+
39+
func (s *stream) CloseWrite() error {
40+
return s.mplex().CloseWrite()
41+
}
42+
43+
func (s *stream) CloseRead() error {
44+
return s.mplex().CloseRead()
45+
}
46+
47+
func (s *stream) Reset() error {
48+
return s.mplex().Reset()
49+
}
50+
51+
func (s *stream) SetDeadline(t time.Time) error {
52+
return s.mplex().SetDeadline(t)
53+
}
54+
55+
func (s *stream) SetReadDeadline(t time.Time) error {
56+
return s.mplex().SetReadDeadline(t)
57+
}
58+
59+
func (s *stream) SetWriteDeadline(t time.Time) error {
60+
return s.mplex().SetWriteDeadline(t)
61+
}
62+
63+
func (s *stream) mplex() *mp.Stream {
64+
return (*mp.Stream)(s)
65+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/transport.go
2+
package mplex
3+
4+
import (
5+
"net"
6+
7+
"github.com/libp2p/go-libp2p/core/network"
8+
9+
mp "github.com/libp2p/go-mplex"
10+
)
11+
12+
// DefaultTransport has default settings for Transport
13+
var DefaultTransport = &Transport{}
14+
15+
const ID = "/mplex/6.7.0"
16+
17+
var _ network.Multiplexer = &Transport{}
18+
19+
// Transport implements mux.Multiplexer that constructs
20+
// mplex-backed muxed connections.
21+
type Transport struct{}
22+
23+
func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) {
24+
m, err := mp.NewMultiplex(nc, isServer, scope)
25+
if err != nil {
26+
return nil, err
27+
}
28+
return NewMuxedConn(m), nil
29+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/transport_test.go
2+
package mplex
3+
4+
import (
5+
"errors"
6+
"net"
7+
"testing"
8+
9+
"github.com/libp2p/go-libp2p/core/network"
10+
test "github.com/libp2p/go-libp2p/p2p/muxer/testsuite"
11+
)
12+
13+
func TestDefaultTransport(t *testing.T) {
14+
test.SubtestAll(t, DefaultTransport)
15+
}
16+
17+
type memoryScope struct {
18+
network.PeerScope
19+
limit int
20+
reserved int
21+
}
22+
23+
func (m *memoryScope) ReserveMemory(size int, prio uint8) error {
24+
if m.reserved+size > m.limit {
25+
return errors.New("too much")
26+
}
27+
m.reserved += size
28+
return nil
29+
}
30+
31+
func (m *memoryScope) ReleaseMemory(size int) {
32+
m.reserved -= size
33+
if m.reserved < 0 {
34+
panic("too much memory released")
35+
}
36+
}
37+
38+
type memoryLimitedTransport struct {
39+
Transport
40+
}
41+
42+
func (t *memoryLimitedTransport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) {
43+
return t.Transport.NewConn(nc, isServer, &memoryScope{
44+
limit: 3 * 1 << 20,
45+
PeerScope: scope,
46+
})
47+
}
48+
49+
func TestDefaultTransportWithMemoryLimit(t *testing.T) {
50+
test.SubtestAll(t, &memoryLimitedTransport{
51+
Transport: *DefaultTransport,
52+
})
53+
}

core/node/libp2p/routingopt_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ import (
88
)
99

1010
func TestHttpAddrsFromConfig(t *testing.T) {
11-
require.Equal(t, []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic"},
11+
require.Equal(t, []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1"},
1212
httpAddrsFromConfig(config.Addresses{
13-
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic"},
13+
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1"},
1414
}), "Swarm addrs should be taken by default")
1515

1616
require.Equal(t, []string{"/ip4/192.168.0.1/tcp/4001"},
1717
httpAddrsFromConfig(config.Addresses{
18-
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic"},
18+
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1"},
1919
Announce: []string{"/ip4/192.168.0.1/tcp/4001"},
2020
}), "Announce addrs should override Swarm if specified")
2121

22-
require.Equal(t, []string{"/ip4/0.0.0.0/udp/4001/quic"},
22+
require.Equal(t, []string{"/ip4/0.0.0.0/udp/4001/quic-v1"},
2323
httpAddrsFromConfig(config.Addresses{
24-
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic"},
24+
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1"},
2525
NoAnnounce: []string{"/ip4/0.0.0.0/tcp/4001"},
2626
}), "Swarm addrs should not contain NoAnnounce addrs")
2727

2828
require.Equal(t, []string{"/ip4/192.168.0.1/tcp/4001", "/ip4/192.168.0.2/tcp/4001"},
2929
httpAddrsFromConfig(config.Addresses{
30-
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic"},
30+
Swarm: []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic-v1"},
3131
Announce: []string{"/ip4/192.168.0.1/tcp/4001"},
3232
AppendAnnounce: []string{"/ip4/192.168.0.2/tcp/4001"},
3333
}), "AppendAnnounce addrs should be included if specified")

0 commit comments

Comments
 (0)