From 39571d22d20e2e396af244aff9e6d7b42d12aeac Mon Sep 17 00:00:00 2001 From: DylanYong Date: Sat, 24 Jun 2023 16:42:32 +0800 Subject: [PATCH] docs: fix some comments errors --- core/crypto/rsa_go.go | 2 +- core/event/network.go | 2 +- core/host/host.go | 2 +- core/network/errors.go | 2 +- core/network/network.go | 8 +++++--- core/network/rcmgr.go | 11 +++++------ core/peer/addrinfo.go | 2 +- core/peer/peer.go | 2 +- core/peer/record.go | 6 +++--- core/peerstore/peerstore.go | 4 ++-- core/pnet/codec.go | 2 +- core/record/envelope.go | 2 +- core/routing/query.go | 2 +- core/routing/routing.go | 2 +- core/sec/insecure/insecure.go | 2 +- core/transport/transport.go | 2 +- 16 files changed, 27 insertions(+), 26 deletions(-) diff --git a/core/crypto/rsa_go.go b/core/crypto/rsa_go.go index efac25d712..bfbd987bee 100644 --- a/core/crypto/rsa_go.go +++ b/core/crypto/rsa_go.go @@ -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) diff --git a/core/event/network.go b/core/event/network.go index e7f15726cc..37dd09ca9a 100644 --- a/core/event/network.go +++ b/core/event/network.go @@ -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 diff --git a/core/host/host.go b/core/host/host.go index 33e3cd33d4..7990f7f456 100644 --- a/core/host/host.go +++ b/core/host/host.go @@ -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 diff --git a/core/network/errors.go b/core/network/errors.go index 2209ee2332..03bb90c266 100644 --- a/core/network/errors.go +++ b/core/network/errors.go @@ -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") diff --git a/core/network/network.go b/core/network/network.go index 13c24ff2ff..7137b9de86 100644 --- a/core/network/network.go +++ b/core/network/network.go @@ -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] } @@ -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] } @@ -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] } diff --git a/core/network/rcmgr.go b/core/network/rcmgr.go index 934905e250..992a3875c9 100644 --- a/core/network/rcmgr.go +++ b/core/network/rcmgr.go @@ -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. // @@ -69,7 +69,7 @@ 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. @@ -77,8 +77,7 @@ import ( // or dynamic. // // WARNING The ResourceManager interface is considered experimental and subject to change -// -// in subsequent releases. +// in subsequent releases. type ResourceManager interface { ResourceScopeViewer @@ -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 @@ -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 diff --git a/core/peer/addrinfo.go b/core/peer/addrinfo.go index b479df9e06..fba4cfd0eb 100644 --- a/core/peer/addrinfo.go +++ b/core/peer/addrinfo.go @@ -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, "" diff --git a/core/peer/peer.go b/core/peer/peer.go index 7bd4f8d245..f7f649f24d 100644 --- a/core/peer/peer.go +++ b/core/peer/peer.go @@ -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)) diff --git a/core/peer/record.go b/core/peer/record.go index 0fc7e552db..49d89e146f 100644 --- a/core/peer/record.go +++ b/core/peer/record.go @@ -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} @@ -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} diff --git a/core/peerstore/peerstore.go b/core/peerstore/peerstore.go index e28383b394..4c9227f811 100644 --- a/core/peerstore/peerstore.go +++ b/core/peerstore/peerstore.go @@ -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 @@ -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 diff --git a/core/pnet/codec.go b/core/pnet/codec.go index e741aba995..2ff1e7628c 100644 --- a/core/pnet/codec.go +++ b/core/pnet/codec.go @@ -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 } diff --git a/core/record/envelope.go b/core/record/envelope.go index 21127a5b97..2ad01718e3 100644 --- a/core/record/envelope.go +++ b/core/record/envelope.go @@ -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) diff --git a/core/routing/query.go b/core/routing/query.go index 72791b5274..a99eccaef0 100644 --- a/core/routing/query.go +++ b/core/routing/query.go @@ -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 diff --git a/core/routing/routing.go b/core/routing/routing.go index 07437b5dff..e1d47451d6 100644 --- a/core/routing/routing.go +++ b/core/routing/routing.go @@ -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. // diff --git a/core/sec/insecure/insecure.go b/core/sec/insecure/insecure.go index 9ed20f093e..9d4fe11792 100644 --- a/core/sec/insecure/insecure.go +++ b/core/sec/insecure/insecure.go @@ -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 diff --git a/core/transport/transport.go b/core/transport/transport.go index 859c6d6088..89a9608d41 100644 --- a/core/transport/transport.go +++ b/core/transport/transport.go @@ -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