separate download and upload handler
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build !go1.13
|
||||
// +build !go1.13
|
||||
|
||||
package bencode
|
||||
|
@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build go1.13
|
||||
// +build go1.13
|
||||
|
||||
package bencode
|
||||
|
@ -317,12 +317,12 @@ func (s *Server) Node6Num() int { return s.routingTable6.Len() }
|
||||
// AddNode adds the node into the routing table.
|
||||
//
|
||||
// The returned value:
|
||||
// NodeAdded: The node is added successfully.
|
||||
// NodeNotAdded: The node is not added and is discarded.
|
||||
// NodeExistAndUpdated: The node has existed, and its status has been updated.
|
||||
// NodeExistAndChanged: The node has existed, but the address is inconsistent.
|
||||
// The current node will be discarded.
|
||||
//
|
||||
// NodeAdded: The node is added successfully.
|
||||
// NodeNotAdded: The node is not added and is discarded.
|
||||
// NodeExistAndUpdated: The node has existed, and its status has been updated.
|
||||
// NodeExistAndChanged: The node has existed, but the address is inconsistent.
|
||||
// The current node will be discarded.
|
||||
func (s *Server) AddNode(node krpc.Node) int {
|
||||
// For IPv6
|
||||
if node.Addr.IsIPv6() {
|
||||
|
@ -155,12 +155,12 @@ func (rt *routingTable) Stop() {
|
||||
// AddNode adds the node into the routing table.
|
||||
//
|
||||
// The returned value:
|
||||
// NodeAdded: The node is added successfully.
|
||||
// NodeNotAdded: The node is not added and is discarded.
|
||||
// NodeExistAndUpdated: The node has existed, and its status has been updated.
|
||||
// NodeExistAndChanged: The node has existed, but the address is inconsistent.
|
||||
// The current node will be discarded.
|
||||
//
|
||||
// NodeAdded: The node is added successfully.
|
||||
// NodeNotAdded: The node is not added and is discarded.
|
||||
// NodeExistAndUpdated: The node has existed, and its status has been updated.
|
||||
// NodeExistAndChanged: The node has existed, but the address is inconsistent.
|
||||
// The current node will be discarded.
|
||||
func (rt *routingTable) AddNode(n krpc.Node) (r int) {
|
||||
if n.ID == rt.root { // Don't add itself.
|
||||
return NodeNotAdded
|
||||
|
@ -270,7 +270,8 @@ func (a Address) String() string {
|
||||
}
|
||||
|
||||
// Equal reports whether n is equal to o, which is equal to
|
||||
// n.HasIPAndPort(o.IP, o.Port)
|
||||
//
|
||||
// n.HasIPAndPort(o.IP, o.Port)
|
||||
func (a Address) Equal(o Address) bool {
|
||||
return a.Port == o.Port && a.IP.String() == o.IP.String()
|
||||
}
|
||||
|
@ -25,10 +25,11 @@ import (
|
||||
// GenerateAllowedFastSet generates some allowed fast set of the torrent file.
|
||||
//
|
||||
// Argument:
|
||||
// set: generated piece set, the length of which is the number to be generated.
|
||||
// sz: the number of pieces in torrent.
|
||||
// ip: the of the remote peer of the connection.
|
||||
// infohash: infohash of torrent.
|
||||
//
|
||||
// set: generated piece set, the length of which is the number to be generated.
|
||||
// sz: the number of pieces in torrent.
|
||||
// ip: the of the remote peer of the connection.
|
||||
// infohash: infohash of torrent.
|
||||
//
|
||||
// BEP 6
|
||||
func GenerateAllowedFastSet(set []uint32, sz uint32, ip net.IP, infohash metainfo.Hash) {
|
||||
|
@ -31,9 +31,7 @@ type BlockUploadHandler struct {
|
||||
}
|
||||
|
||||
// NewBlockUploadHandler returns a new BlockUploadHandler.
|
||||
func NewBlockUploadHandler(info metainfo.Info,
|
||||
onBlock func(pieceIndex, pieceOffset uint32, b []byte) error,
|
||||
respondBlock func(c *pp.PeerConn) error) BlockUploadHandler {
|
||||
func NewBlockUploadHandler(info metainfo.Info, onBlock func(pieceIndex, pieceOffset uint32, b []byte) error, respondBlock func(c *pp.PeerConn) error) BlockUploadHandler {
|
||||
return BlockUploadHandler{
|
||||
Info: info,
|
||||
OnBlock: onBlock,
|
Reference in New Issue
Block a user