Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed PeerConnectAlert type and SocketType values #248

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* improved java api layer

2.1.0-30

* update to libtorrent master
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/libtorrent4j/BDecodeNode.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2018-2023, Alden Torres
*
* Licensed under the terms of the MIT license.
* Copy of the license at https://opensource.org/licenses/MIT
*/

package org.libtorrent4j;

import org.libtorrent4j.swig.bdecode_node;
Expand Down Expand Up @@ -39,7 +46,7 @@ public bdecode_node swig() {
}

/**
* This methods returns the internal buffer or null
* This method returns the internal buffer or null
* if it was constructed without one.
* <p>
* This also prevent premature garbage collection in case
Expand Down
99 changes: 9 additions & 90 deletions src/main/java/org/libtorrent4j/alerts/IncomingConnectionAlert.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
/*
* Copyright (c) 2018-2023, Alden Torres
*
* Licensed under the terms of the MIT license.
* Copy of the license at https://opensource.org/licenses/MIT
*/

package org.libtorrent4j.alerts;

import org.libtorrent4j.TcpEndpoint;
import org.libtorrent4j.swig.incoming_connection_alert;

/**
* The incoming connection alert is posted every time we successfully accept
* an incoming connection, through any mean. The most straigh-forward ways
* an incoming connection, through any mean. The most straight-forward ways
* of accepting incoming connections are through the TCP listen socket and
* the UDP listen socket for uTP sockets. However, connections may also be
* accepted ofer a Socks5 or i2p listen socket, or via a torrent specific
* accepted through a Socks5 or i2p listen socket, or via a torrent specific
* listen socket for SSL torrents.
*
* @author gubatron
Expand Down Expand Up @@ -37,92 +44,4 @@ public SocketType socketType() {
public TcpEndpoint endpoint() {
return new TcpEndpoint(alert.get_endpoint());
}

/**
*
*/
public enum SocketType {

/**
* no socket instantiated.
*/
NONE(0),

/**
*
*/
TCP(1),

/**
*
*/
SOCKS5(2),

/**
*
*/
HTTP(3),

/**
*
*/
UTP(4),

/**
*
*/
I2P(5),

/**
*
*/
SSL_TCP(6),

/**
*
*/
SSL_SOCKS5(7),

/**
* Like SSL_HTTP.
*/
HTTPS(8),

/**
*
*/
SSL_UTP(9),

/**
*
*/
UNKNOWN(-1);

SocketType(int swigValue) {
this.swigValue = swigValue;
}

private final int swigValue;

/**
* @return the native value
*/
public int swig() {
return swigValue;
}

/**
* @param swigValue the native value
* @return the java enum
*/
public static SocketType fromSwig(int swigValue) {
SocketType[] enumValues = SocketType.class.getEnumConstants();
for (SocketType ev : enumValues) {
if (ev.swig() == swigValue) {
return ev;
}
}
return UNKNOWN;
}
}
}
72 changes: 68 additions & 4 deletions src/main/java/org/libtorrent4j/alerts/PeerConnectAlert.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
/*
* Copyright (c) 2018-2023, Alden Torres
*
* Licensed under the terms of the MIT license.
* Copy of the license at https://opensource.org/licenses/MIT
*/

package org.libtorrent4j.alerts;

import org.libtorrent4j.swig.peer_connect_alert;
import org.libtorrent4j.swig.socket_type_t;

/**
* This alert is posted every time an outgoing peer connect attempts succeeds.
* This alert is posted every time an incoming peer connection both
* successfully passes the protocol handshake and is associated with a
* torrent, or an outgoing peer connection attempt succeeds. For arbitrary
* incoming connections, see {@link IncomingConnectionAlert}.
*
* @author gubatron
* @author aldenml
Expand All @@ -15,7 +24,62 @@ public final class PeerConnectAlert extends PeerAlert<peer_connect_alert> {
super(alert);
}

public socket_type_t socketType() {
return alert.getSocket_type();
/**
* Tells you if the peer was incoming or outgoing.
*/
public Direction direction() {
return Direction.fromSwig(alert.getDirection().swigValue());
}

public SocketType socketType() {
return SocketType.fromSwig(alert.getSocket_type().swigValue());
}

/**
*
*/
public enum Direction {

/**
*
*/
IN(peer_connect_alert.direction_t.in.swigValue()),

/**
*
*/
OUT(peer_connect_alert.direction_t.out.swigValue()),

/**
*
*/
UNKNOWN(-1);

Direction(int swigValue) {
this.swigValue = swigValue;
}

private final int swigValue;

/**
* @return the native value
*/
public int swig() {
return swigValue;
}

/**
* @param swigValue the native value
* @return the java enum
*/
public static PeerConnectAlert.Direction fromSwig(int swigValue) {
PeerConnectAlert.Direction[] enumValues = PeerConnectAlert.Direction.class.getEnumConstants();
for (PeerConnectAlert.Direction ev : enumValues) {
if (ev.swig() == swigValue) {
return ev;
}
}
return UNKNOWN;
}
}
}
29 changes: 28 additions & 1 deletion src/main/java/org/libtorrent4j/alerts/SocketType.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/*
* Copyright (c) 2018-2023, Alden Torres
*
* Licensed under the terms of the MIT license.
* Copy of the license at https://opensource.org/licenses/MIT
*/

package org.libtorrent4j.alerts;

import org.libtorrent4j.swig.socket_type_t;

/**
*
* The kinds of sockets involved in various operations or events.
*/
public enum SocketType {

Expand Down Expand Up @@ -32,11 +39,31 @@ public enum SocketType {
*/
SOCKS5(socket_type_t.socks5.swigValue()),

/**
*
*/
SOCKS5_SSL(socket_type_t.socks5_ssl.swigValue()),

/**
*
*/
UTP_SSL(socket_type_t.utp_ssl.swigValue()),

/**
*
*/
HTTP(socket_type_t.http.swigValue()),

/**
*
*/
HTTP_SSL(socket_type_t.http_ssl.swigValue()),

/**
*
*/
RTC(socket_type_t.rtc.swigValue()),

/**
*
*/
Expand Down