Documentation ¶
Overview ¶
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- type Manager
- func (m *Manager) Clear(i int)
- func (m *Manager) ClearPeer(peerID core.PeerID)
- func (m *Manager) GetFailedRequests() []Request
- func (m *Manager) MarkInvalid(peerID core.PeerID, i int)
- func (m *Manager) MarkUnsent(peerID core.PeerID, i int)
- func (m *Manager) PendingPieces(peerID core.PeerID) []int
- func (m *Manager) ReservePieces(peerID core.PeerID, candidates *bitset.BitSet, ...) ([]int, error)
- type Request
- type Status
Constants ¶
const DefaultPolicy = "default"
DefaultPolicy randomly selects pieces to request.
const RarestFirstPolicy = "rarest_first"
RarestFirstPolicy selects pieces that the fewest of our peers have to request first.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
Manager encapsulates thread-safe piece request bookkeeping. It is not responsible for sending nor receiving pieces in any way.
func NewManager ¶
func NewManager( clk clock.Clock, timeout time.Duration, policy string, pipelineLimit int) (*Manager, error)
NewManager creates a new Manager.
func (*Manager) Clear ¶
Clear deletes the piece request for piece i. Should be used for freeing up unneeded request bookkeeping.
func (*Manager) GetFailedRequests ¶
GetFailedRequests returns a copy of all failed piece requests.
func (*Manager) MarkInvalid ¶
MarkInvalid marks the piece request for piece i as invalid.
func (*Manager) MarkUnsent ¶
MarkUnsent marks the piece request for piece i as unsent.
func (*Manager) PendingPieces ¶
PendingPieces returns the pieces for all pending requests to peerID in sorted order. Intended primarily for testing purposes.
func (*Manager) ReservePieces ¶
func (m *Manager) ReservePieces( peerID core.PeerID, candidates *bitset.BitSet, numPeersByPiece syncutil.Counters, allowDuplicates bool) ([]int, error)
ReservePieces selects the next piece(s) to be requested from given peer. It selects peers on a rarity-first basis using numPeersByPiece. If allowDuplicates is set, may return pieces which have already been reserved under other peers.
type Request ¶
type Request struct { Piece int PeerID core.PeerID Status Status // contains filtered or unexported fields }
Request represents a piece request to peer.
type Status ¶
type Status int
Status enumerates possible statuses of a Request.
const ( // StatusPending denotes a valid request which is still in-flight. StatusPending Status = iota // StatusExpired denotes an in-flight request which has timed out on our end. StatusExpired // StatusUnsent denotes an unsent request that is safe to retry to the same peer. StatusUnsent // StatusInvalid denotes a completed request that resulted in an invalid payload. StatusInvalid )