Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #31 from ipfs/feat/fix-comments
Browse files Browse the repository at this point in the history
docs(comments): end comment sentences to have full-stop
  • Loading branch information
Stebalien authored Dec 7, 2018
2 parents 03f4615 + 5235c8d commit 99e83c7
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 74 deletions.
8 changes: 4 additions & 4 deletions bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []cid.Cid) (<-chan blocks
return out, nil
}

// CancelWant removes a given key from the wantlist
// CancelWant removes a given key from the wantlist.
func (bs *Bitswap) CancelWants(cids []cid.Cid, ses uint64) {
if len(cids) == 0 {
return
Expand Down Expand Up @@ -363,7 +363,7 @@ func (bs *Bitswap) receiveBlockFrom(blk blocks.Block, from peer.ID) error {
return nil
}

// SessionsForBlock returns a slice of all sessions that may be interested in the given cid
// SessionsForBlock returns a slice of all sessions that may be interested in the given cid.
func (bs *Bitswap) SessionsForBlock(c cid.Cid) []*Session {
var out []*Session
bs.sm.IterateSessions(func(session exchange.Fetcher) {
Expand Down Expand Up @@ -442,14 +442,14 @@ func (bs *Bitswap) updateReceiveCounters(b blocks.Block) {
}
}

// Connected/Disconnected warns bitswap about peer connections
// Connected/Disconnected warns bitswap about peer connections.
func (bs *Bitswap) PeerConnected(p peer.ID) {
initialWants := bs.wm.CurrentBroadcastWants()
bs.pm.Connected(p, initialWants)
bs.engine.PeerConnected(p)
}

// Connected/Disconnected warns bitswap about peer connections
// Connected/Disconnected warns bitswap about peer connections.
func (bs *Bitswap) PeerDisconnected(p peer.ID) {
bs.pm.Disconnected(p)
bs.engine.PeerDisconnected(p)
Expand Down
8 changes: 4 additions & 4 deletions decision/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ const (
maxMessageSize = 512 * 1024
)

// Envelope contains a message for a Peer
// Envelope contains a message for a Peer.
type Envelope struct {
// Peer is the intended recipient
// Peer is the intended recipient.
Peer peer.ID

// Message is the payload
// Message is the payload.
Message bsmsg.BitSwapMessage

// A callback to notify the decision queue that the task is complete
Expand Down Expand Up @@ -206,7 +206,7 @@ func (e *Engine) Outbox() <-chan (<-chan *Envelope) {
return e.outbox
}

// Returns a slice of Peers with whom the local node has active sessions
// Peers returns a slice of Peers with whom the local node has active sessions.
func (e *Engine) Peers() []peer.ID {
e.lock.Lock()
defer e.lock.Unlock()
Expand Down
16 changes: 8 additions & 8 deletions decision/peer_request_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type prq struct {
frozen map[peer.ID]*activePartner
}

// Push currently adds a new peerRequestTask to the end of the list
// Push currently adds a new peerRequestTask to the end of the list.
func (tl *prq) Push(to peer.ID, entries ...*wantlist.Entry) {
tl.lock.Lock()
defer tl.lock.Unlock()
Expand Down Expand Up @@ -140,7 +140,7 @@ func (tl *prq) Pop() *peerRequestTask {
return out
}

// Remove removes a task from the queue
// Remove removes a task from the queue.
func (tl *prq) Remove(k cid.Cid, p peer.ID) {
tl.lock.Lock()
t, ok := tl.taskMap[taskEntryKey{p, k}]
Expand Down Expand Up @@ -210,12 +210,12 @@ type peerRequestTask struct {
index int // book-keeping field used by the pq container
}

// Index implements pq.Elem
// Index implements pq.Elem.
func (t *peerRequestTask) Index() int {
return t.index
}

// SetIndex implements pq.Elem
// SetIndex implements pq.Elem.
func (t *peerRequestTask) SetIndex(i int) {
t.index = i
}
Expand Down Expand Up @@ -307,15 +307,15 @@ func partnerCompare(a, b pq.Elem) bool {
return pa.active < pb.active
}

// StartTask signals that a task was started for this partner
// StartTask signals that a task was started for this partner.
func (p *activePartner) StartTask(k cid.Cid) {
p.activelk.Lock()
p.activeBlocks.Add(k)
p.active++
p.activelk.Unlock()
}

// TaskDone signals that a task was completed for this partner
// TaskDone signals that a task was completed for this partner.
func (p *activePartner) TaskDone(k cid.Cid) {
p.activelk.Lock()
p.activeBlocks.Remove(k)
Expand All @@ -326,12 +326,12 @@ func (p *activePartner) TaskDone(k cid.Cid) {
p.activelk.Unlock()
}

// Index implements pq.Elem
// Index implements pq.Elem.
func (p *activePartner) Index() int {
return p.index
}

// SetIndex implements pq.Elem
// SetIndex implements pq.Elem.
func (p *activePartner) SetIndex(i int) {
p.index = i
}
2 changes: 1 addition & 1 deletion message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type BitSwapMessage interface {
// the sender.
Wantlist() []Entry

// Blocks returns a slice of unique blocks
// Blocks returns a slice of unique blocks.
Blocks() []blocks.Block

// AddEntry adds an entry to the Wantlist.
Expand Down
16 changes: 8 additions & 8 deletions messagequeue/messagequeue.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
var log = logging.Logger("bitswap")

// MessageNetwork is any network that can connect peers and generate a message
// sender
// sender.
type MessageNetwork interface {
ConnectTo(context.Context, peer.ID) error
NewMessageSender(context.Context, peer.ID) (bsnet.MessageSender, error)
}

// MessageQueue implements queuee of want messages to send to peers
// MessageQueue implements queue of want messages to send to peers.
type MessageQueue struct {
p peer.ID

Expand All @@ -38,7 +38,7 @@ type MessageQueue struct {
done chan struct{}
}

// New creats a new MessageQueues
// New creats a new MessageQueue.
func New(p peer.ID, network MessageNetwork) *MessageQueue {
return &MessageQueue{
done: make(chan struct{}),
Expand All @@ -50,19 +50,19 @@ func New(p peer.ID, network MessageNetwork) *MessageQueue {
}
}

// RefIncrement increments the refcount for a message queue
// RefIncrement increments the refcount for a message queue.
func (mq *MessageQueue) RefIncrement() {
mq.refcnt++
}

// RefDecrement decrements the refcount for a message queue and returns true
// if the refcount is now 0
// if the refcount is now 0.
func (mq *MessageQueue) RefDecrement() bool {
mq.refcnt--
return mq.refcnt > 0
}

// AddMessage adds new entries to an outgoing message for a given session
// AddMessage adds new entries to an outgoing message for a given session.
func (mq *MessageQueue) AddMessage(entries []*bsmsg.Entry, ses uint64) {
if !mq.addEntries(entries, ses) {
return
Expand All @@ -74,7 +74,7 @@ func (mq *MessageQueue) AddMessage(entries []*bsmsg.Entry, ses uint64) {
}

// Startup starts the processing of messages, and creates an initial message
// based on the given initial wantlist
// based on the given initial wantlist.
func (mq *MessageQueue) Startup(ctx context.Context, initialEntries []*wantlist.Entry) {

// new peer, we will want to give them our full wantlist
Expand All @@ -93,7 +93,7 @@ func (mq *MessageQueue) Startup(ctx context.Context, initialEntries []*wantlist.

}

// Shutdown stops the processing of messages for a message queue
// Shutdown stops the processing of messages for a message queue.
func (mq *MessageQueue) Shutdown() {
close(mq.done)
}
Expand Down
10 changes: 5 additions & 5 deletions network/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
ProtocolBitswap protocol.ID = "/ipfs/bitswap/1.1.0"
)

// BitSwapNetwork provides network connectivity for BitSwap sessions
// BitSwapNetwork provides network connectivity for BitSwap sessions.
type BitSwapNetwork interface {

// SendMessage sends a BitSwap message to a peer.
Expand Down Expand Up @@ -49,7 +49,7 @@ type MessageSender interface {
Reset() error
}

// Implement Receiver to receive messages from the BitSwapNetwork
// Implement Receiver to receive messages from the BitSwapNetwork.
type Receiver interface {
ReceiveMessage(
ctx context.Context,
Expand All @@ -58,16 +58,16 @@ type Receiver interface {

ReceiveError(error)

// Connected/Disconnected warns bitswap about peer connections
// Connected/Disconnected warns bitswap about peer connections.
PeerConnected(peer.ID)
PeerDisconnected(peer.ID)
}

type Routing interface {
// FindProvidersAsync returns a channel of providers for the given key
// FindProvidersAsync returns a channel of providers for the given key.
FindProvidersAsync(context.Context, cid.Cid, int) <-chan peer.ID

// Provide provides the key to the network
// Provide provides the key to the network.
Provide(context.Context, cid.Cid) error
}

Expand Down
4 changes: 2 additions & 2 deletions network/ipfs_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var log = logging.Logger("bitswap_network")

var sendMessageTimeout = time.Minute * 10

// NewFromIpfsHost returns a BitSwapNetwork supported by underlying IPFS host
// NewFromIpfsHost returns a BitSwapNetwork supported by underlying IPFS host.
func NewFromIpfsHost(host host.Host, r routing.ContentRouting) BitSwapNetwork {
bitswapNetwork := impl{
host: host,
Expand Down Expand Up @@ -149,7 +149,7 @@ func (bsnet *impl) ConnectTo(ctx context.Context, p peer.ID) error {
return bsnet.host.Connect(ctx, pstore.PeerInfo{ID: p})
}

// FindProvidersAsync returns a channel of providers for the given key
// FindProvidersAsync returns a channel of providers for the given key.
func (bsnet *impl) FindProvidersAsync(ctx context.Context, k cid.Cid, max int) <-chan peer.ID {

// Since routing queries are expensive, give bitswap the peers to which we
Expand Down
22 changes: 11 additions & 11 deletions peermanager/peermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
metricsBuckets = []float64{1 << 6, 1 << 10, 1 << 14, 1 << 18, 1<<18 + 15, 1 << 22}
)

// PeerQueue provides a queer of messages to be sent for a single peer
// PeerQueue provides a queer of messages to be sent for a single peer.
type PeerQueue interface {
RefIncrement()
RefDecrement() bool
Expand All @@ -25,14 +25,14 @@ type PeerQueue interface {
Shutdown()
}

// PeerQueueFactory provides a function that will create a PeerQueue
// PeerQueueFactory provides a function that will create a PeerQueue.
type PeerQueueFactory func(p peer.ID) PeerQueue

type peerMessage interface {
handle(pm *PeerManager)
}

// PeerManager manages a pool of peers and sends messages to peers in the pool
// PeerManager manages a pool of peers and sends messages to peers in the pool.
type PeerManager struct {
// sync channel for Run loop
peerMessages chan peerMessage
Expand All @@ -45,7 +45,7 @@ type PeerManager struct {
cancel func()
}

// New creates a new PeerManager, given a context and a peerQueueFactory
// New creates a new PeerManager, given a context and a peerQueueFactory.
func New(ctx context.Context, createPeerQueue PeerQueueFactory) *PeerManager {
ctx, cancel := context.WithCancel(ctx)
return &PeerManager{
Expand All @@ -57,32 +57,32 @@ func New(ctx context.Context, createPeerQueue PeerQueueFactory) *PeerManager {
}
}

// ConnectedPeers returns a list of peers this PeerManager is managing
// ConnectedPeers returns a list of peers this PeerManager is managing.
func (pm *PeerManager) ConnectedPeers() []peer.ID {
resp := make(chan []peer.ID)
pm.peerMessages <- &getPeersMessage{resp}
return <-resp
}

// Connected is called to add a new peer to the pool, and send it an initial set
// of wants
// of wants.
func (pm *PeerManager) Connected(p peer.ID, initialEntries []*wantlist.Entry) {
select {
case pm.peerMessages <- &connectPeerMessage{p, initialEntries}:
case <-pm.ctx.Done():
}
}

// Disconnected is called to remove a peer from the pool
// Disconnected is called to remove a peer from the pool.
func (pm *PeerManager) Disconnected(p peer.ID) {
select {
case pm.peerMessages <- &disconnectPeerMessage{p}:
case <-pm.ctx.Done():
}
}

// SendMessage is called to send a message to all or some peers in the pool
// if targets is nil, it sends to all
// SendMessage is called to send a message to all or some peers in the pool;
// if targets is nil, it sends to all.
func (pm *PeerManager) SendMessage(entries []*bsmsg.Entry, targets []peer.ID, from uint64) {
select {
case pm.peerMessages <- &sendPeerMessage{entries: entries, targets: targets, from: from}:
Expand All @@ -91,12 +91,12 @@ func (pm *PeerManager) SendMessage(entries []*bsmsg.Entry, targets []peer.ID, fr
}

// Startup enables the run loop for the PeerManager - no processing will occur
// if startup is not called
// if startup is not called.
func (pm *PeerManager) Startup() {
go pm.run()
}

// Shutdown shutsdown processing for the PeerManager
// Shutdown shutsdown processing for the PeerManager.
func (pm *PeerManager) Shutdown() {
pm.cancel()
}
Expand Down
6 changes: 3 additions & 3 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const activeWantsLimit = 16

// Session holds state for an individual bitswap transfer operation.
// This allows bitswap to make smarter decisions about who to send wantlist
// info to, and who to request blocks from
// info to, and who to request blocks from.
type Session struct {
ctx context.Context
tofetch *cidQueue
Expand Down Expand Up @@ -51,7 +51,7 @@ type Session struct {
}

// NewSession creates a new bitswap session whose lifetime is bounded by the
// given context
// given context.
func (bs *Bitswap) NewSession(ctx context.Context) exchange.Fetcher {
s := &Session{
activePeers: make(map[peer.ID]struct{}),
Expand Down Expand Up @@ -302,7 +302,7 @@ func (s *Session) GetBlocks(ctx context.Context, keys []cid.Cid) (<-chan blocks.
return getBlocksImpl(ctx, keys, s.notif, s.fetch, s.cancelWants)
}

// GetBlock fetches a single block
// GetBlock fetches a single block.
func (s *Session) GetBlock(parent context.Context, k cid.Cid) (blocks.Block, error) {
return getBlock(parent, k, s.GetBlocks)
}
Expand Down
2 changes: 1 addition & 1 deletion sessionmanager/sessionmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (sm *SessionManager) GetNextSessionID() uint64 {
type IterateSessionFunc func(session exchange.Fetcher)

// IterateSessions loops through all managed sessions and applies the given
// IterateSessionFunc
// IterateSessionFunc.
func (sm *SessionManager) IterateSessions(iterate IterateSessionFunc) {
sm.sessLk.Lock()
defer sm.sessLk.Unlock()
Expand Down
Loading

0 comments on commit 99e83c7

Please sign in to comment.