Skip to content

Commit

Permalink
Merge branch 'master' into add-autotls-example
Browse files Browse the repository at this point in the history
  • Loading branch information
p-shahi authored Feb 11, 2025
2 parents f44f4ef + 080e6c8 commit 2b8b7f7
Show file tree
Hide file tree
Showing 93 changed files with 2,131 additions and 879 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go-test-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
run: test_analysis ${{ env.GOTESTFLAGS }}
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}_${{ matrix.go }}_test_results.db
path: ./test_results.db
Expand All @@ -131,7 +131,7 @@ jobs:
run: test_analysis -race ${{ env.GORACEFLAGS }} ./...
- name: Upload test results (Race)
if: (steps.race.conclusion == 'success' || steps.race.conclusion == 'failure')
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}_${{ matrix.go }}_test_results_race.db
path: ./test_results.db
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ concurrency:

jobs:
release-check:
uses: marcopolo/unified-github-workflows/.github/workflows/release-check.yml@e66cb9667a2e1148efda4591e29c56258eaf385b
uses: ipdxco/unified-github-workflows/.github/workflows/release-check.yml@v1.0
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,25 @@ Guidelines:
- ask questions or talk about things in our [discussion forums](https://discuss.libp2p.io), or open an [issue](https://github.com/libp2p/go-libp2p/issues) for bug reports, or #libp2p-implementers on [Filecoin slack](https://filecoin.io/slack).
- ensure you are able to contribute (no legal issues please -- we use the DCO)
- get in touch with @libp2p/go-libp2p-maintainers about how best to contribute
- No drive-by contributions seeking to collect airdrops.
- Many projects aim to reward contributors to common goods. Great. However,
this creates an unfortunate incentive for low-effort PRs, submitted solely to
claim rewards. These PRs consume maintainers’ time and energy to triage, with
little to no impact on end users. If we suspect this is the intent of a PR,
we may close it without comment. If you believe this was done in error,
contact us via email. Reference this README section and explain why your PR
is not a “drive-by contribution.”
- have fun!

There's a few things you can do right now to help out:
- Go through the modules below and **check out existing issues**. This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
- **Perform code reviews**.
- **Add tests**. There can never be enough tests.
- Go through the modules below and **check out existing issues**. This would
be especially useful for modules in active development. Some knowledge of
IPFS/libp2p may be required, as well as the infrastructure behind it - for
instance, you may need to read up on p2p and more complex operations like
muxing to be able to help technically.


## Supported Go Versions

Expand Down
34 changes: 29 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,9 @@ func (cfg *Config) newBasicHost(swrm *swarm.Swarm, eventBus event.Bus) (*bhost.B
return h, nil
}

// NewNode constructs a new libp2p Host from the Config.
//
// This function consumes the config. Do not reuse it (really!).
func (cfg *Config) NewNode() (host.Host, error) {
func (cfg *Config) validate() error {
if cfg.EnableAutoRelay && !cfg.Relay {
return nil, fmt.Errorf("cannot enable autorelay; relay is not enabled")
return fmt.Errorf("cannot enable autorelay; relay is not enabled")
}
// If possible check that the resource manager conn limit is higher than the
// limit set in the conn manager.
Expand All @@ -462,6 +459,33 @@ func (cfg *Config) NewNode() (host.Host, error) {
}
}

if len(cfg.PSK) > 0 && cfg.ShareTCPListener {
return errors.New("cannot use shared TCP listener with PSK")
}

return nil
}

// NewNode constructs a new libp2p Host from the Config.
//
// This function consumes the config. Do not reuse it (really!).
func (cfg *Config) NewNode() (host.Host, error) {

validateErr := cfg.validate()
if validateErr != nil {
if cfg.ResourceManager != nil {
cfg.ResourceManager.Close()
}
if cfg.ConnManager != nil {
cfg.ConnManager.Close()
}
if cfg.Peerstore != nil {
cfg.Peerstore.Close()
}

return nil, validateErr
}

if !cfg.DisableMetrics {
rcmgr.MustRegisterWith(cfg.PrometheusRegisterer)
}
Expand Down
34 changes: 16 additions & 18 deletions core/crypto/pb/crypto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions core/network/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,60 @@ package network

import (
"context"
"fmt"
"io"

ic "github.com/libp2p/go-libp2p/core/crypto"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"

ma "github.com/multiformats/go-multiaddr"
)

type ConnErrorCode uint32

type ConnError struct {
Remote bool
ErrorCode ConnErrorCode
TransportError error
}

func (c *ConnError) Error() string {
side := "local"
if c.Remote {
side = "remote"
}
if c.TransportError != nil {
return fmt.Sprintf("connection closed (%s): code: 0x%x: transport error: %s", side, c.ErrorCode, c.TransportError)
}
return fmt.Sprintf("connection closed (%s): code: 0x%x", side, c.ErrorCode)
}

func (c *ConnError) Is(target error) bool {
if tce, ok := target.(*ConnError); ok {
return tce.ErrorCode == c.ErrorCode && tce.Remote == c.Remote
}
return false
}

func (c *ConnError) Unwrap() []error {
return []error{ErrReset, c.TransportError}
}

const (
ConnNoError ConnErrorCode = 0
ConnProtocolNegotiationFailed ConnErrorCode = 0x1000
ConnResourceLimitExceeded ConnErrorCode = 0x1001
ConnRateLimited ConnErrorCode = 0x1002
ConnProtocolViolation ConnErrorCode = 0x1003
ConnSupplanted ConnErrorCode = 0x1004
ConnGarbageCollected ConnErrorCode = 0x1005
ConnShutdown ConnErrorCode = 0x1006
ConnGated ConnErrorCode = 0x1007
ConnCodeOutOfRange ConnErrorCode = 0x1008
)

// Conn is a connection to a remote peer. It multiplexes streams.
// Usually there is no need to use a Conn directly, but it may
// be useful to get information about the peer on the other side:
Expand All @@ -24,6 +69,11 @@ type Conn interface {
ConnStat
ConnScoper

// CloseWithError closes the connection with errCode. The errCode is sent to the
// peer on a best effort basis. For transports that do not support sending error
// codes on connection close, the behavior is identical to calling Close.
CloseWithError(errCode ConnErrorCode) error

// ID returns an identifier that uniquely identifies this Conn within this
// host, during this run. Connection IDs may repeat across restarts.
ID() string
Expand Down
53 changes: 53 additions & 0 deletions core/network/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package network
import (
"context"
"errors"
"fmt"
"io"
"net"
"time"
Expand All @@ -11,6 +12,49 @@ import (
// ErrReset is returned when reading or writing on a reset stream.
var ErrReset = errors.New("stream reset")

type StreamErrorCode uint32

type StreamError struct {
ErrorCode StreamErrorCode
Remote bool
TransportError error
}

func (s *StreamError) Error() string {
side := "local"
if s.Remote {
side = "remote"
}
if s.TransportError != nil {
return fmt.Sprintf("stream reset (%s): code: 0x%x: transport error: %s", side, s.ErrorCode, s.TransportError)
}
return fmt.Sprintf("stream reset (%s): code: 0x%x", side, s.ErrorCode)
}

func (s *StreamError) Is(target error) bool {
if tse, ok := target.(*StreamError); ok {
return tse.ErrorCode == s.ErrorCode && tse.Remote == s.Remote
}
return false
}

func (s *StreamError) Unwrap() []error {
return []error{ErrReset, s.TransportError}
}

const (
StreamNoError StreamErrorCode = 0
StreamProtocolNegotiationFailed StreamErrorCode = 0x1001
StreamResourceLimitExceeded StreamErrorCode = 0x1002
StreamRateLimited StreamErrorCode = 0x1003
StreamProtocolViolation StreamErrorCode = 0x1004
StreamSupplanted StreamErrorCode = 0x1005
StreamGarbageCollected StreamErrorCode = 0x1006
StreamShutdown StreamErrorCode = 0x1007
StreamGated StreamErrorCode = 0x1008
StreamCodeOutOfRange StreamErrorCode = 0x1009
)

// MuxedStream is a bidirectional io pipe within a connection.
type MuxedStream interface {
io.Reader
Expand Down Expand Up @@ -56,6 +100,11 @@ type MuxedStream interface {
// side to hang up and go away.
Reset() error

// ResetWithError aborts both ends of the stream with `errCode`. `errCode` is sent
// to the peer on a best effort basis. For transports that do not support sending
// error codes to remote peer, the behavior is identical to calling Reset
ResetWithError(errCode StreamErrorCode) error

SetDeadline(time.Time) error
SetReadDeadline(time.Time) error
SetWriteDeadline(time.Time) error
Expand All @@ -75,6 +124,10 @@ type MuxedConn interface {
// Close closes the stream muxer and the the underlying net.Conn.
io.Closer

// CloseWithError closes the connection with errCode. The errCode is sent
// to the peer.
CloseWithError(errCode ConnErrorCode) error

// IsClosed returns whether a connection is fully closed, so it can
// be garbage collected.
IsClosed() bool
Expand Down
4 changes: 4 additions & 0 deletions core/network/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ type Stream interface {

// Scope returns the user's view of this stream's resource scope
Scope() StreamScope

// ResetWithError closes both ends of the stream with errCode. The errCode is sent
// to the peer.
ResetWithError(errCode StreamErrorCode) error
}
Loading

0 comments on commit 2b8b7f7

Please sign in to comment.