Skip to content

Commit

Permalink
docs: fix some comments errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhaoyu committed Jun 24, 2023
1 parent acca7a6 commit 39571d2
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion core/crypto/rsa_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (pk *RsaPublicKey) Raw() (res []byte, err error) {

// Equals checks whether this key is equal to another
func (pk *RsaPublicKey) Equals(k Key) bool {
// make sure this is an rsa public key
// make sure this is a rsa public key
other, ok := (k).(*RsaPublicKey)
if !ok {
return basicEquals(pk, k)
Expand Down
2 changes: 1 addition & 1 deletion core/event/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
//
// Explanation: There were two connections and one was cut. This connection
// might have been in active use but neither peer will observe a change in
// "connectedness". Peers should always make sure to re-try network requests.
// "connectedness". Peers should always make sure to retry network requests.
type EvtPeerConnectednessChanged struct {
// Peer is the remote peer whose connectedness has changed.
Peer peer.ID
Expand Down
2 changes: 1 addition & 1 deletion core/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Host interface {
// SetStreamHandler sets the protocol handler on the Host's Mux.
// This is equivalent to:
// host.Mux().SetHandler(proto, handler)
// (Threadsafe)
// (Thread-safe)
SetStreamHandler(pid protocol.ID, handler network.StreamHandler)

// SetStreamHandlerMatch sets the protocol handler on the Host's Mux
Expand Down
2 changes: 1 addition & 1 deletion core/network/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ var ErrTransientConn = errors.New("transient connection to peer")
// exceed system resource limits.
var ErrResourceLimitExceeded = temporaryError("resource limit exceeded")

// ErrResourceScopeClosed is returned when attemptig to reserve resources in a closed resource
// ErrResourceScopeClosed is returned when attempting to reserve resources in a closed resource
// scope.
var ErrResourceScopeClosed = errors.New("resource scope closed")
8 changes: 5 additions & 3 deletions core/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ const (
DirOutbound
)

const unrecognized = "(unrecognized)"

func (d Direction) String() string {
str := [...]string{"Unknown", "Inbound", "Outbound"}
if d < 0 || int(d) >= len(str) {
return "(unrecognized)"
return unrecognized
}
return str[d]
}
Expand All @@ -66,7 +68,7 @@ const (
func (c Connectedness) String() string {
str := [...]string{"NotConnected", "Connected", "CanConnect", "CannotConnect"}
if c < 0 || int(c) >= len(str) {
return "(unrecognized)"
return unrecognized
}
return str[c]
}
Expand All @@ -93,7 +95,7 @@ const (
func (r Reachability) String() string {
str := [...]string{"Unknown", "Public", "Private"}
if r < 0 || int(r) >= len(str) {
return "(unrecognized)"
return unrecognized
}
return str[r]
}
Expand Down
11 changes: 5 additions & 6 deletions core/network/rcmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// +---------------------------> Stream
//
// The basic resources accounted by the ResourceManager include memory, streams, connections,
// and file descriptors. These account for both space and time used by
// and file descriptors. These account for both space and time used by
// the stack, as each resource has a direct effect on the system
// availability and performance.
//
Expand Down Expand Up @@ -69,16 +69,15 @@ import (
// service scope using the ResourceManager interface.
// - Applications that want to account for their network resource usage can reserve memory,
// typically using a span, directly in the System or a Service scope; they can also
// opt to use appropriate steam scopes for streams that they create or own.
// opt to use appropriate stream scopes for streams that they create or own.
//
// User Serviceable Parts: the user has the option to specify their own implementation of the
// interface. We provide a canonical implementation in the go-libp2p-resource-manager package.
// The user of that package can specify limits for the various scopes, which can be static
// or dynamic.
//
// WARNING The ResourceManager interface is considered experimental and subject to change
//
// in subsequent releases.
// in subsequent releases.
type ResourceManager interface {
ResourceScopeViewer

Expand Down Expand Up @@ -110,7 +109,7 @@ type ResourceScopeViewer interface {

// ViewTransient views the transient (DMZ) resource scope.
// The transient scope accounts for resources that are in the process of
// full establishment. For instance, a new connection prior to the
// full establishment. For instance, a new connection prior to the
// handshake does not belong to any peer, but it still needs to be
// constrained as this opens an avenue for attacks in transient resource
// usage. Similarly, a stream that has not negotiated a protocol yet is
Expand Down Expand Up @@ -155,7 +154,7 @@ type ResourceScope interface {
// For instance, a muxer growing a window buffer will use a low priority and only grow the buffer
// if there is no memory pressure in the system.
//
// The are 4 predefined priority levels, Low, Medium, High and Always,
// There are 4 predefined priority levels, Low, Medium, High and Always,
// capturing common patterns, but the user is free to use any granularity applicable to his case.
ReserveMemory(size int, prio uint8) error

Expand Down
2 changes: 1 addition & 1 deletion core/peer/addrinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func AddrInfosFromP2pAddrs(maddrs ...ma.Multiaddr) ([]AddrInfo, error) {
// SplitAddr splits a p2p Multiaddr into a transport multiaddr and a peer ID.
//
// * Returns a nil transport if the address only contains a /p2p part.
// * Returns a empty peer ID if the address doesn't contain a /p2p part.
// * Returns an empty peer ID if the address doesn't contain a /p2p part.
func SplitAddr(m ma.Multiaddr) (transport ma.Multiaddr, id ID) {
if m == nil {
return nil, ""
Expand Down
2 changes: 1 addition & 1 deletion core/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (id ID) MatchesPublicKey(pk ic.PubKey) bool {

// ExtractPublicKey attempts to extract the public key from an ID.
//
// This method returns ErrNoPublicKey if the peer ID looks valid but it can't extract
// This method returns ErrNoPublicKey if the peer ID looks valid, but it can't extract
// the public key.
func (id ID) ExtractPublicKey() (ic.PubKey, error) {
decoded, err := mh.Decode([]byte(id))
Expand Down
6 changes: 3 additions & 3 deletions core/peer/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func init() {
record.RegisterType(&PeerRecord{})
}

// PeerRecordEnvelopeDomain is the domain string used for peer records contained in a Envelope.
// PeerRecordEnvelopeDomain is the domain string used for peer records contained in an Envelope.
const PeerRecordEnvelopeDomain = "libp2p-peer-record"

// PeerRecordEnvelopePayloadType is the type hint used to identify peer records in a Envelope.
// PeerRecordEnvelopePayloadType is the type hint used to identify peer records in an Envelope.
// Defined in https://github.com/multiformats/multicodec/blob/master/table.csv
// with name "libp2p-peer-record".
var PeerRecordEnvelopePayloadType = []byte{0x03, 0x01}
Expand Down Expand Up @@ -58,7 +58,7 @@ var PeerRecordEnvelopePayloadType = []byte{0x03, 0x01}
// routing.Envelope, and PeerRecord implements the routing.Record interface
// to facilitate this.
//
// To share a PeerRecord, first call Sign to wrap the record in a Envelope
// To share a PeerRecord, first call Sign to wrap the record in an Envelope
// and sign it with the local peer's private key:
//
// rec := &PeerRecord{PeerID: myPeerId, Addrs: myAddrs}
Expand Down
4 changes: 2 additions & 2 deletions core/peerstore/peerstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
ConnectedAddrTTL
)

// Peerstore provides a threadsafe store of Peer related
// Peerstore provides a thread-safe store of Peer related
// information.
type Peerstore interface {
io.Closer
Expand Down Expand Up @@ -174,7 +174,7 @@ type CertifiedAddrBook interface {
// added via ConsumePeerRecord.
ConsumePeerRecord(s *record.Envelope, ttl time.Duration) (accepted bool, err error)

// GetPeerRecord returns a Envelope containing a PeerRecord for the
// GetPeerRecord returns an Envelope containing a PeerRecord for the
// given peer id, if one exists.
// Returns nil if no signed PeerRecord exists for the peer.
GetPeerRecord(p peer.ID) *record.Envelope
Expand Down
2 changes: 1 addition & 1 deletion core/pnet/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func expectHeader(r *bufio.Reader, expected []byte) error {
return err
}
if !bytes.Equal(header, expected) {
return fmt.Errorf("expected file header %s, got: %s", pathPSKv1, header)
return fmt.Errorf("expected file header %s, got: %s", expected, header)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/record/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func UnmarshalEnvelope(data []byte) (*Envelope, error) {
}

// Marshal returns a byte slice containing a serialized protobuf representation
// of a Envelope.
// of an Envelope.
func (e *Envelope) Marshal() (res []byte, err error) {
defer func() { catch.HandlePanic(recover(), &err, "libp2p envelope marshal") }()
key, err := crypto.PublicKeyToProto(e.PublicKey)
Expand Down
2 changes: 1 addition & 1 deletion core/routing/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func PublishQueryEvent(ctx context.Context, ev *QueryEvent) {
}

// SubscribesToQueryEvents returns true if the context subscribes to query
// events. If this function returns falls, calling `PublishQueryEvent` on the
// events. If this function returns false, calling `PublishQueryEvent` on the
// context will be a no-op.
func SubscribesToQueryEvents(ctx context.Context) bool {
return ctx.Value(routingQueryKey{}) != nil
Expand Down
2 changes: 1 addition & 1 deletion core/routing/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type ValueStore interface {
GetValue(context.Context, string, ...Option) ([]byte, error)

// SearchValue searches for better and better values from this value
// store corresponding to the given Key. By default implementations must
// store corresponding to the given Key. By default, implementations must
// stop the search after a good value is found. A 'good' value is a value
// that would be returned from GetValue.
//
Expand Down
2 changes: 1 addition & 1 deletion core/sec/insecure/insecure.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package insecure provides an insecure, unencrypted implementation of the the SecureConn and SecureTransport interfaces.
// Package insecure provides an insecure, unencrypted implementation of the SecureConn and SecureTransport interfaces.
//
// Recommended only for testing and other non-production usage.
package insecure
Expand Down
2 changes: 1 addition & 1 deletion core/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type CapableConn interface {
// For a conceptual overview, see https://docs.libp2p.io/concepts/transport/
type Transport interface {
// Dial dials a remote peer. It should try to reuse local listener
// addresses if possible but it may choose not to.
// addresses if possible, but it may choose not to.
Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (CapableConn, error)

// CanDial returns true if this transport knows how to dial the given
Expand Down

0 comments on commit 39571d2

Please sign in to comment.