Skip to content

Commit 928252c

Browse files
committed
Merge branch 'master' into marco/bring-go-nat-home
2 parents 3c079e6 + f88beca commit 928252c

File tree

98 files changed

+2053
-720
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2053
-720
lines changed

.github/workflows/go-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717
go-check:
1818
uses: ipdxco/unified-github-workflows/.github/workflows/[email protected]
1919
with:
20-
go-version: "1.22.x"
20+
go-version: "1.24.x"
2121
go-generate-ignore-protoc-version-comments: true

.github/workflows/go-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ jobs:
1717
go-test:
1818
uses: ./.github/workflows/go-test-template.yml
1919
with:
20-
go-versions: '["1.22.x", "1.23.x"]'
20+
go-versions: '["1.23.x", "1.24.x"]'
2121
secrets:
2222
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ func (cfg *Config) NewNode() (host.Host, error) {
532532
}
533533
fxopts = append(fxopts, transportOpts...)
534534

535-
// Configure routing and autorelay
535+
// Configure routing
536536
if cfg.Routing != nil {
537537
fxopts = append(fxopts,
538538
fx.Provide(cfg.Routing),

core/crypto/pb/crypto.pb.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/event/addrs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,8 @@ type EvtLocalAddressesUpdated struct {
8181
// wrapped in a record.Envelope and signed by the Host's private key.
8282
SignedPeerRecord *record.Envelope
8383
}
84+
85+
// EvtAutoRelayAddrsUpdated is sent by the autorelay when the node's relay addresses are updated
86+
type EvtAutoRelayAddrsUpdated struct {
87+
RelayAddrs []ma.Multiaddr
88+
}

core/network/conn.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,60 @@ package network
22

33
import (
44
"context"
5+
"fmt"
56
"io"
67

78
ic "github.com/libp2p/go-libp2p/core/crypto"
9+
810
"github.com/libp2p/go-libp2p/core/peer"
911
"github.com/libp2p/go-libp2p/core/protocol"
1012

1113
ma "github.com/multiformats/go-multiaddr"
1214
)
1315

16+
type ConnErrorCode uint32
17+
18+
type ConnError struct {
19+
Remote bool
20+
ErrorCode ConnErrorCode
21+
TransportError error
22+
}
23+
24+
func (c *ConnError) Error() string {
25+
side := "local"
26+
if c.Remote {
27+
side = "remote"
28+
}
29+
if c.TransportError != nil {
30+
return fmt.Sprintf("connection closed (%s): code: 0x%x: transport error: %s", side, c.ErrorCode, c.TransportError)
31+
}
32+
return fmt.Sprintf("connection closed (%s): code: 0x%x", side, c.ErrorCode)
33+
}
34+
35+
func (c *ConnError) Is(target error) bool {
36+
if tce, ok := target.(*ConnError); ok {
37+
return tce.ErrorCode == c.ErrorCode && tce.Remote == c.Remote
38+
}
39+
return false
40+
}
41+
42+
func (c *ConnError) Unwrap() []error {
43+
return []error{ErrReset, c.TransportError}
44+
}
45+
46+
const (
47+
ConnNoError ConnErrorCode = 0
48+
ConnProtocolNegotiationFailed ConnErrorCode = 0x1000
49+
ConnResourceLimitExceeded ConnErrorCode = 0x1001
50+
ConnRateLimited ConnErrorCode = 0x1002
51+
ConnProtocolViolation ConnErrorCode = 0x1003
52+
ConnSupplanted ConnErrorCode = 0x1004
53+
ConnGarbageCollected ConnErrorCode = 0x1005
54+
ConnShutdown ConnErrorCode = 0x1006
55+
ConnGated ConnErrorCode = 0x1007
56+
ConnCodeOutOfRange ConnErrorCode = 0x1008
57+
)
58+
1459
// Conn is a connection to a remote peer. It multiplexes streams.
1560
// Usually there is no need to use a Conn directly, but it may
1661
// be useful to get information about the peer on the other side:
@@ -24,6 +69,11 @@ type Conn interface {
2469
ConnStat
2570
ConnScoper
2671

72+
// CloseWithError closes the connection with errCode. The errCode is sent to the
73+
// peer on a best effort basis. For transports that do not support sending error
74+
// codes on connection close, the behavior is identical to calling Close.
75+
CloseWithError(errCode ConnErrorCode) error
76+
2777
// ID returns an identifier that uniquely identifies this Conn within this
2878
// host, during this run. Connection IDs may repeat across restarts.
2979
ID() string

core/network/mux.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package network
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"io"
78
"net"
89
"time"
@@ -11,6 +12,49 @@ import (
1112
// ErrReset is returned when reading or writing on a reset stream.
1213
var ErrReset = errors.New("stream reset")
1314

15+
type StreamErrorCode uint32
16+
17+
type StreamError struct {
18+
ErrorCode StreamErrorCode
19+
Remote bool
20+
TransportError error
21+
}
22+
23+
func (s *StreamError) Error() string {
24+
side := "local"
25+
if s.Remote {
26+
side = "remote"
27+
}
28+
if s.TransportError != nil {
29+
return fmt.Sprintf("stream reset (%s): code: 0x%x: transport error: %s", side, s.ErrorCode, s.TransportError)
30+
}
31+
return fmt.Sprintf("stream reset (%s): code: 0x%x", side, s.ErrorCode)
32+
}
33+
34+
func (s *StreamError) Is(target error) bool {
35+
if tse, ok := target.(*StreamError); ok {
36+
return tse.ErrorCode == s.ErrorCode && tse.Remote == s.Remote
37+
}
38+
return false
39+
}
40+
41+
func (s *StreamError) Unwrap() []error {
42+
return []error{ErrReset, s.TransportError}
43+
}
44+
45+
const (
46+
StreamNoError StreamErrorCode = 0
47+
StreamProtocolNegotiationFailed StreamErrorCode = 0x1001
48+
StreamResourceLimitExceeded StreamErrorCode = 0x1002
49+
StreamRateLimited StreamErrorCode = 0x1003
50+
StreamProtocolViolation StreamErrorCode = 0x1004
51+
StreamSupplanted StreamErrorCode = 0x1005
52+
StreamGarbageCollected StreamErrorCode = 0x1006
53+
StreamShutdown StreamErrorCode = 0x1007
54+
StreamGated StreamErrorCode = 0x1008
55+
StreamCodeOutOfRange StreamErrorCode = 0x1009
56+
)
57+
1458
// MuxedStream is a bidirectional io pipe within a connection.
1559
type MuxedStream interface {
1660
io.Reader
@@ -56,6 +100,11 @@ type MuxedStream interface {
56100
// side to hang up and go away.
57101
Reset() error
58102

103+
// ResetWithError aborts both ends of the stream with `errCode`. `errCode` is sent
104+
// to the peer on a best effort basis. For transports that do not support sending
105+
// error codes to remote peer, the behavior is identical to calling Reset
106+
ResetWithError(errCode StreamErrorCode) error
107+
59108
SetDeadline(time.Time) error
60109
SetReadDeadline(time.Time) error
61110
SetWriteDeadline(time.Time) error
@@ -75,6 +124,10 @@ type MuxedConn interface {
75124
// Close closes the stream muxer and the the underlying net.Conn.
76125
io.Closer
77126

127+
// CloseWithError closes the connection with errCode. The errCode is sent
128+
// to the peer.
129+
CloseWithError(errCode ConnErrorCode) error
130+
78131
// IsClosed returns whether a connection is fully closed, so it can
79132
// be garbage collected.
80133
IsClosed() bool

core/network/stream.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ type Stream interface {
2727

2828
// Scope returns the user's view of this stream's resource scope
2929
Scope() StreamScope
30+
31+
// ResetWithError closes both ends of the stream with errCode. The errCode is sent
32+
// to the peer.
33+
ResetWithError(errCode StreamErrorCode) error
3034
}

core/peer/pb/peer_record.pb.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/record/pb/envelope.pb.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)