-
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tracker] Allow comparing peers using PeerId
We still default to using IPAddress/Port as some bittorrent clients randomise their peerid, making it a little use suitable to use as a unique identifier.
- Loading branch information
1 parent
2ee0e41
commit 7bcd469
Showing
4 changed files
with
104 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// IPAddressComparer.cs | ||
// ClientAddressComparer.cs | ||
// | ||
// Authors: | ||
// Alan McGovern <[email protected]> | ||
|
@@ -29,13 +29,16 @@ | |
|
||
namespace MonoTorrent.Tracker | ||
{ | ||
public interface IPeerComparer | ||
{ | ||
object GetKey(AnnounceRequest parameters); | ||
} | ||
|
||
class IPAddressComparer : IPeerComparer | ||
/// <summary> | ||
/// Uses the <see cref="AnnounceRequest.ClientAddress"/> field to compare peers when handling Announce or Scrape requests. | ||
/// </summary> | ||
public class ClientAddressComparer : IPeerComparer | ||
{ | ||
/// <summary> | ||
/// Returns the <see cref="AnnounceRequest.ClientAddress"/> field to use to compare peers. | ||
/// </summary> | ||
/// <param name="parameters">The data sent as part of the Announce request</param> | ||
/// <returns></returns> | ||
public object GetKey(AnnounceRequest parameters) | ||
{ | ||
return parameters.ClientAddress; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// IPeerComparer.cs | ||
// | ||
// Authors: | ||
// Alan McGovern <[email protected]> | ||
// | ||
// Copyright (C) 2006 Alan McGovern | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// | ||
|
||
|
||
namespace MonoTorrent.Tracker | ||
{ | ||
/// <summary> | ||
/// Returns one of the properties from a peers <see cref="AnnounceRequest"/>, or a value derived from | ||
/// properties on the <see cref="AnnounceRequest"/>, to use when comparing peers. | ||
/// </summary> | ||
public interface IPeerComparer | ||
{ | ||
/// <summary> | ||
/// Returns one of the properties from the <see cref="AnnounceRequest"/> object, or a value derived from | ||
/// properties on the <see cref="AnnounceRequest"/> object, to use when comparing peers. | ||
/// </summary> | ||
/// <param name="parameters">The data sent as part of the Announce request</param> | ||
/// <returns></returns> | ||
object GetKey(AnnounceRequest parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// PeerIdComparer.cs | ||
// | ||
// Authors: | ||
// Alan McGovern <[email protected]> | ||
// | ||
// Copyright (C) 2019 Alan McGovern | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// | ||
|
||
|
||
namespace MonoTorrent.Tracker | ||
{ | ||
/// <summary> | ||
/// Uses the <see cref="AnnounceRequest.PeerId"/> field to compare peers when handling Announce or Scrape requests. | ||
/// </summary> | ||
public class PeerIdComparer : IPeerComparer | ||
{ | ||
/// <summary> | ||
/// Returns the <see cref="AnnounceRequest.PeerId"/> field to use to compare peers. | ||
/// </summary> | ||
/// <param name="parameters">The data sent as part of the Announce request</param> | ||
/// <returns></returns> | ||
public object GetKey(AnnounceRequest parameters) | ||
{ | ||
return parameters.PeerId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters