Package com.frostwire.jlibtorrent
Class UdpEndpoint
java.lang.Object
com.frostwire.jlibtorrent.UdpEndpoint
- All Implemented Interfaces:
Cloneable
A network address and UDP port pair for DHT and uTP protocol communication.
UdpEndpoint represents a remote node's address and UDP port in the DHT network
or for uTP (Micro Transport Protocol) connections. Unlike TcpEndpoint which is used
for traditional BitTorrent peer connections on TCP, UdpEndpoint identifies nodes participating
in the Distributed Hash Table (DHT) or peers using the uTP protocol over UDP.
Understanding UDP Endpoints:
UDP endpoints represent peer/node locations for UDP-based protocols:
- DHT Communication: DHT operations use UDP to query remote nodes
- DHT Node Discovery: DHT bootstrap and lookups return lists of UdpEndpoints
- uTP Connections: Alternative to TCP using UDP with Micro Transport Protocol
- Address Format: Supports both IPv4 (192.168.1.1:6881) and IPv6 addresses
Creating UDP Endpoints:
// From IPv4 address and port
UdpEndpoint dhtNode1 = new UdpEndpoint("203.0.113.50", 6881);
System.out.println(dhtNode1); // Output: udp://203.0.113.50:6881
// From IPv6 address
UdpEndpoint dhtNode2 = new UdpEndpoint("2001:db8::8a2e:370:7334", 6881);
System.out.println(dhtNode2); // Output: udp://2001:db8::8a2e:370:7334:6881
// From Address object
Address dhtNodeAddr = new Address("151.101.1.140");
UdpEndpoint bootstrapNode = new UdpEndpoint(dhtNodeAddr, 6881);
// Create empty endpoint (useful for initialization)
UdpEndpoint empty = new UdpEndpoint();
Querying Endpoint Information:
UdpEndpoint node = new UdpEndpoint("162.125.18.133", 6881);
// Get the address component
Address addr = node.address();
boolean isV4 = addr.isV4(); // true for IPv4
boolean isV6 = addr.isV6(); // true for IPv6
String ipString = addr.toString();
// Get the port
int port = node.port(); // 6881
// Get full string representation with udp:// prefix
String fullAddr = node.toString(); // "udp://162.125.18.133:6881"
DHT Bootstrap Nodes:
Bootstrap nodes are well-known DHT nodes used to join the DHT network:
SessionManager sm = new SessionManager();
sm.start();
// Common DHT bootstrap nodes (well-known, public DHT nodes)
UdpEndpoint[] bootstrapNodes = {
new UdpEndpoint("router.bittorrent.com", 6881),
new UdpEndpoint("dht.transmissionbt.com", 6881),
new UdpEndpoint("router.utorrent.com", 6881),
new UdpEndpoint("208.67.72.220", 6881) // OpenDNS
};
// Bootstrap DHT by adding these nodes to routing table
for (UdpEndpoint node : bootstrapNodes) {
try {
sm.dhtBootstrap(node);
} catch (Exception e) {
System.out.println("Could not connect to " + node);
}
}
DHT Lookup Operations:
// Perform DHT lookup (uses UDP endpoints internally)
Sha1Hash infoHash = new Sha1Hash("d8e8fca2dc0f896fd7cb4cb0031ba249");
java.util.ArrayList<TcpEndpoint> peers = sm.dhtGetPeers(infoHash, 20);
// The DHT communicates with UDP endpoints to find these TCP peers
DHT Routing Table Statistics:
// Monitor DHT bucket population (uses UdpEndpoints internally)
sm.addListener(new AlertListener() {
public int[] types() {
return new int[] {AlertType.DHT_STATS.swig()};
}
public void alert(Alert<?> alert) {
DhtStatsAlert a = (DhtStatsAlert) alert;
List<DhtRoutingBucket> buckets = a.routingBuckets();
int totalNodes = 0;
for (DhtRoutingBucket bucket : buckets) {
totalNodes += bucket.numNodes();
// Each node tracked is conceptually a UdpEndpoint
}
System.out.println("DHT routing table has \" + totalNodes + \" nodes\");
}
});
Comparison: TCP Endpoint vs UDP Endpoint:
┌─────────────────────────────┬─────────────────┬──────────────────┐ │ Characteristic │ TcpEndpoint │ UdpEndpoint │ ├─────────────────────────────┼─────────────────┼──────────────────┤ │ Protocol │ TCP │ UDP │ │ Purpose │ Peer data xfer │ DHT/uTP │ │ Connection State │ Connected │ Connectionless │ │ String Format │ 192.168.1.1:80 │ udp://192....:80 │ │ IPv6 Format │ [::1]:80 │ [::1]:80 │ │ Typical BitTorrent Usage │ Blocks exchange │ Node discovery │ │ Number per Peer │ 1 per torrent │ Many (DHT) │ └─────────────────────────────┴─────────────────┴──────────────────┘
Performance Notes:
- UDP endpoints are lightweight and frequently created/destroyed
- DHT operations may create thousands of UdpEndpoint references internally
- String constructor performs IP address validation; invalid IPs throw immediately
- Cloning is supported for creating copies of endpoint references
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionUdpEndpoint(Address address, int port) UdpEndpoint(com.frostwire.jlibtorrent.swig.udp_endpoint endp) UdpEndpoint(String ip, int port) -
Method Summary
-
Constructor Details
-
UdpEndpoint
public UdpEndpoint(com.frostwire.jlibtorrent.swig.udp_endpoint endp) -
UdpEndpoint
public UdpEndpoint() -
UdpEndpoint
-
UdpEndpoint
-
-
Method Details