piecerequest

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
const DefaultPolicy = "default"

DefaultPolicy randomly selects pieces to request.

View Source
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

type Manager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func (m *Manager) Clear(i int)

Clear deletes the piece request for piece i. Should be used for freeing up unneeded request bookkeeping.

func (*Manager) ClearPeer

func (m *Manager) ClearPeer(peerID core.PeerID)

ClearPeer deletes all piece requests for peerID.

func (*Manager) GetFailedRequests

func (m *Manager) GetFailedRequests() []Request

GetFailedRequests returns a copy of all failed piece requests.

func (*Manager) MarkInvalid

func (m *Manager) MarkInvalid(peerID core.PeerID, i int)

MarkInvalid marks the piece request for piece i as invalid.

func (*Manager) MarkUnsent

func (m *Manager) MarkUnsent(peerID core.PeerID, i int)

MarkUnsent marks the piece request for piece i as unsent.

func (*Manager) PendingPieces

func (m *Manager) PendingPieces(peerID core.PeerID) []int

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL