Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

deprecate this repo #281

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# DEPRECATION NOTICE

This package has moved into go-libp2p as a sub-package, `github.com/libp2p/go-libp2p/core`.


# go-libp2p-core

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai)
Expand Down
32 changes: 19 additions & 13 deletions alias.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
// Deprecated: This package has moved into go-libp2p as a sub-package: github.com/libp2p/go-libp2p/core.
//
// Package core provides convenient access to foundational, central go-libp2p primitives via type aliases.
package core

import (
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
"github.com/multiformats/go-multiaddr"
"github.com/libp2p/go-libp2p/core"
)

// Multiaddr aliases the Multiaddr type from github.com/multiformats/go-multiaddr.
//
// Refer to the docs on that type for more info.
type Multiaddr = multiaddr.Multiaddr
// Deprecated: use github.com/libp2p/go-libp2p/core.Multiaddr instead
type Multiaddr = core.Multiaddr

// PeerID aliases peer.ID.
//
// Refer to the docs on that type for more info.
type PeerID = peer.ID
// Deprecated: use github.com/libp2p/go-libp2p/core.PeerID instead
type PeerID = core.PeerID

// ProtocolID aliases protocol.ID.
//
// Refer to the docs on that type for more info.
type ProtocolID = protocol.ID
// Deprecated: use github.com/libp2p/go-libp2p/core.ProtocolID instead
type ProtocolID = core.ProtocolID

// PeerAddrInfo aliases peer.AddrInfo.
//
// Refer to the docs on that type for more info.
type PeerAddrInfo = peer.AddrInfo
// Deprecated: use github.com/libp2p/go-libp2p/core.PeerAddrInfo instead
type PeerAddrInfo = core.PeerAddrInfo

// Host aliases host.Host.
//
// Refer to the docs on that type for more info.
type Host = host.Host
// Deprecated: use github.com/libp2p/go-libp2p/core.Host instead
type Host = core.Host

// Network aliases network.Network.
//
// Refer to the docs on that type for more info.
type Network = network.Network
// Deprecated: use github.com/libp2p/go-libp2p/core.Network instead
type Network = core.Network

// Conn aliases network.Conn.
//
// Refer to the docs on that type for more info.
type Conn = network.Conn
// Deprecated: use github.com/libp2p/go-libp2p/core.Conn instead
type Conn = core.Conn

// Stream aliases network.Stream.
//
// Refer to the docs on that type for more info.
type Stream = network.Stream
// Deprecated: use github.com/libp2p/go-libp2p/core.Stream instead
type Stream = core.Stream
37 changes: 10 additions & 27 deletions canonicallog/canonicallog.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
// Deprecated: This package has moved into go-libp2p as a sub-package: github.com/libp2p/go-libp2p/core/canonicallog.
package canonicallog

import (
"fmt"
"math/rand"
"net"
"strings"

logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/canonicallog"
"github.com/libp2p/go-libp2p/core/peer"

"github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
)

var log = logging.WithSkip(logging.Logger("canonical-log"), 1)

// LogMisbehavingPeer is the canonical way to log a misbehaving peer.
// Protocols should use this to identify a misbehaving peer to allow the end
// user to easily identify these nodes across protocols and libp2p.
// Deprecated: use github.com/libp2p/go-libp2p/core/canonicallog.LogMisbehavingPeer instead
func LogMisbehavingPeer(p peer.ID, peerAddr multiaddr.Multiaddr, component string, err error, msg string) {
log.Warnf("CANONICAL_MISBEHAVING_PEER: peer=%s addr=%s component=%s err=%q msg=%q", p, peerAddr.String(), component, err, msg)
canonicallog.LogMisbehavingPeer(p, peerAddr, component, err, msg)
}

// LogMisbehavingPeerNetAddr is the canonical way to log a misbehaving peer.
// Protocols should use this to identify a misbehaving peer to allow the end
// user to easily identify these nodes across protocols and libp2p.
// Deprecated: use github.com/libp2p/go-libp2p/core/canonicallog.LogMisbehavingPeerNetAddr instead
func LogMisbehavingPeerNetAddr(p peer.ID, peerAddr net.Addr, component string, originalErr error, msg string) {
ma, err := manet.FromNetAddr(peerAddr)
if err != nil {
log.Warnf("CANONICAL_MISBEHAVING_PEER: peer=%s net_addr=%s component=%s err=%q msg=%q", p, peerAddr.String(), component, originalErr, msg)
return
}

LogMisbehavingPeer(p, ma, component, originalErr, msg)
canonicallog.LogMisbehavingPeerNetAddr(p, peerAddr, component, originalErr, msg)
}

// LogPeerStatus logs any useful information about a peer. It takes in a sample
Expand All @@ -41,16 +33,7 @@ func LogMisbehavingPeerNetAddr(p peer.ID, peerAddr net.Addr, component string, o
// is normal. 10,000 connections from that same IP address is not normal. libp2p
// itself does nothing besides emitting this log. Hook this up to another tool
// like fail2ban to action on the log.
// Deprecated: use github.com/libp2p/go-libp2p/core/canonicallog.LogPeerStatus instead
func LogPeerStatus(sampleRate int, p peer.ID, peerAddr multiaddr.Multiaddr, keyVals ...string) {
if rand.Intn(sampleRate) == 0 {
keyValsStr := strings.Builder{}
for i, kOrV := range keyVals {
if i%2 == 0 {
fmt.Fprintf(&keyValsStr, " %v=", kOrV)
} else {
fmt.Fprintf(&keyValsStr, "%q", kOrV)
}
}
log.Infof("CANONICAL_PEER_STATUS: peer=%s addr=%s sample_rate=%v%s", p, peerAddr.String(), sampleRate, keyValsStr.String())
}
canonicallog.LogPeerStatus(sampleRate, p, peerAddr, keyVals...)
}
25 changes: 0 additions & 25 deletions canonicallog/canonicallog_test.go

This file was deleted.

86 changes: 15 additions & 71 deletions connmgr/decay.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package connmgr

import (
"io"
"time"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/connmgr"
)

// Decayer is implemented by connection managers supporting decaying tags. A
Expand All @@ -22,88 +19,35 @@ import (
// Such a pluggable design affords a great deal of flexibility and versatility.
// Behaviours that are straightforward to implement include:
//
// * Decay a tag by -1, or by half its current value, on every tick.
// * Every time a value is bumped, sum it to its current value.
// * Exponentially boost a score with every bump.
// * Sum the incoming score, but keep it within min, max bounds.
// - Decay a tag by -1, or by half its current value, on every tick.
// - Every time a value is bumped, sum it to its current value.
// - Exponentially boost a score with every bump.
// - Sum the incoming score, but keep it within min, max bounds.
//
// Commonly used DecayFns and BumpFns are provided in this package.
type Decayer interface {
io.Closer

// RegisterDecayingTag creates and registers a new decaying tag, if and only
// if a tag with the supplied name doesn't exist yet. Otherwise, an error is
// returned.
//
// The caller provides the interval at which the tag is refreshed, as well
// as the decay function and the bump function. Refer to godocs on DecayFn
// and BumpFn for more info.
RegisterDecayingTag(name string, interval time.Duration, decayFn DecayFn, bumpFn BumpFn) (DecayingTag, error)
}
// Deprecated: use github.com/libp2p/go-libp2p/core/connmgr.Decayer instead
type Decayer = connmgr.Decayer

// DecayFn applies a decay to the peer's score. The implementation must call
// DecayFn at the interval supplied when registering the tag.
//
// It receives a copy of the decaying value, and returns the score after
// applying the decay, as well as a flag to signal if the tag should be erased.
type DecayFn func(value DecayingValue) (after int, rm bool)
// Deprecated: use github.com/libp2p/go-libp2p/core/connmgr.DecayFn instead
type DecayFn = connmgr.DecayFn

// BumpFn applies a delta onto an existing score, and returns the new score.
//
// Non-trivial bump functions include exponential boosting, moving averages,
// ceilings, etc.
type BumpFn func(value DecayingValue, delta int) (after int)
// Deprecated: use github.com/libp2p/go-libp2p/core/connmgr.BumpFn instead
type BumpFn = connmgr.BumpFn

// DecayingTag represents a decaying tag. The tag is a long-lived general
// object, used to operate on tag values for peers.
type DecayingTag interface {
// Name returns the name of the tag.
Name() string

// Interval is the effective interval at which this tag will tick. Upon
// registration, the desired interval may be overwritten depending on the
// decayer's resolution, and this method allows you to obtain the effective
// interval.
Interval() time.Duration

// Bump applies a delta to a tag value, calling its bump function. The bump
// will be applied asynchronously, and a non-nil error indicates a fault
// when queuing.
Bump(peer peer.ID, delta int) error

// Remove removes a decaying tag from a peer. The removal will be applied
// asynchronously, and a non-nil error indicates a fault when queuing.
Remove(peer peer.ID) error

// Close closes a decaying tag. The Decayer will stop tracking this tag,
// and the state of all peers in the Connection Manager holding this tag
// will be updated.
//
// The deletion is performed asynchronously.
//
// Once deleted, a tag should not be used, and further calls to Bump/Remove
// will error.
//
// Duplicate calls to Remove will not return errors, but a failure to queue
// the first actual removal, will (e.g. when the system is backlogged).
Close() error
}
// Deprecated: use github.com/libp2p/go-libp2p/core/connmgr.DecayingTag instead
type DecayingTag = connmgr.DecayingTag

// DecayingValue represents a value for a decaying tag.
type DecayingValue struct {
// Tag points to the tag this value belongs to.
Tag DecayingTag

// Peer is the peer ID to whom this value is associated.
Peer peer.ID

// Added is the timestamp when this value was added for the first time for
// a tag and a peer.
Added time.Time

// LastVisit is the timestamp of the last visit.
LastVisit time.Time

// Value is the current value of the tag.
Value int
}
// Deprecated: use github.com/libp2p/go-libp2p/core/connmgr.DecayingValue instead
type DecayingValue = connmgr.DecayingValue
75 changes: 18 additions & 57 deletions connmgr/gater.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package connmgr

import (
ma "github.com/multiformats/go-multiaddr"

"github.com/libp2p/go-libp2p-core/control"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/connmgr"
)

// ConnectionGater can be implemented by a type that supports active
Expand All @@ -17,25 +13,25 @@ import (
// of a connection being established/upgraded. Specific functions will be called
// throughout the process, to allow you to intercept the connection at that stage.
//
// InterceptPeerDial is called on an imminent outbound peer dial request, prior
// to the addresses of that peer being available/resolved. Blocking connections
// at this stage is typical for blacklisting scenarios.
// InterceptPeerDial is called on an imminent outbound peer dial request, prior
// to the addresses of that peer being available/resolved. Blocking connections
// at this stage is typical for blacklisting scenarios.
//
// InterceptAddrDial is called on an imminent outbound dial to a peer on a
// particular address. Blocking connections at this stage is typical for
// address filtering.
// InterceptAddrDial is called on an imminent outbound dial to a peer on a
// particular address. Blocking connections at this stage is typical for
// address filtering.
//
// InterceptAccept is called as soon as a transport listener receives an
// inbound connection request, before any upgrade takes place. Transports who
// accept already secure and/or multiplexed connections (e.g. possibly QUIC)
// MUST call this method regardless, for correctness/consistency.
// InterceptAccept is called as soon as a transport listener receives an
// inbound connection request, before any upgrade takes place. Transports who
// accept already secure and/or multiplexed connections (e.g. possibly QUIC)
// MUST call this method regardless, for correctness/consistency.
//
// InterceptSecured is called for both inbound and outbound connections,
// after a security handshake has taken place and we've authenticated the peer.
// InterceptSecured is called for both inbound and outbound connections,
// after a security handshake has taken place and we've authenticated the peer.
//
// InterceptUpgraded is called for inbound and outbound connections, after
// libp2p has finished upgrading the connection entirely to a secure,
// multiplexed channel.
// InterceptUpgraded is called for inbound and outbound connections, after
// libp2p has finished upgrading the connection entirely to a secure,
// multiplexed channel.
//
// This interface can be used to implement *strict/active* connection management
// policies, such as hard limiting of connections once a maximum count has been
Expand All @@ -51,40 +47,5 @@ import (
// as we solidify this feature. The reason why only this method can handle
// DisconnectReasons is that we require stream multiplexing capability to open a
// control protocol stream to transmit the message.
type ConnectionGater interface {

// InterceptPeerDial tests whether we're permitted to Dial the specified peer.
//
// This is called by the network.Network implementation when dialling a peer.
InterceptPeerDial(p peer.ID) (allow bool)

// InterceptAddrDial tests whether we're permitted to dial the specified
// multiaddr for the given peer.
//
// This is called by the network.Network implementation after it has
// resolved the peer's addrs, and prior to dialling each.
InterceptAddrDial(peer.ID, ma.Multiaddr) (allow bool)

// InterceptAccept tests whether an incipient inbound connection is allowed.
//
// This is called by the upgrader, or by the transport directly (e.g. QUIC,
// Bluetooth), straight after it has accepted a connection from its socket.
InterceptAccept(network.ConnMultiaddrs) (allow bool)

// InterceptSecured tests whether a given connection, now authenticated,
// is allowed.
//
// This is called by the upgrader, after it has performed the security
// handshake, and before it negotiates the muxer, or by the directly by the
// transport, at the exact same checkpoint.
InterceptSecured(network.Direction, peer.ID, network.ConnMultiaddrs) (allow bool)

// InterceptUpgraded tests whether a fully capable connection is allowed.
//
// At this point, the connection a multiplexer has been selected.
// When rejecting a connection, the gater can return a DisconnectReason.
// Refer to the godoc on the ConnectionGater type for more information.
//
// NOTE: the go-libp2p implementation currently IGNORES the disconnect reason.
InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)
}
// Deprecated: use github.com/libp2p/go-libp2p/core/connmgr.ConnectionGater instead
type ConnectionGater = connmgr.ConnectionGater
Loading