diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-03-08 22:43:26 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-11-12 17:40:45 +0100 |
commit | d2fdb1697dfcd67540553a2933daa7f63da20d0d (patch) | |
tree | 60c67bd7a0c7e36ed9932ecd001d5cb5cfc3296e /src/main/java | |
parent | 0ebe3fda88f69572f9a8c829a0d8e3b5a76b4238 (diff) |
Use socketfactory and allow caller supplied serversocket
To allow using TrafficStats to tag sockets on Android.
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/lumaserv/bgp/BGPServer.java | 4 | ||||
-rw-r--r-- | src/main/java/com/lumaserv/bgp/BGPSession.java | 8 | ||||
-rw-r--r-- | src/main/java/com/lumaserv/bgp/BGPSessionConfiguration.java | 3 |
3 files changed, 11 insertions, 4 deletions
diff --git a/src/main/java/com/lumaserv/bgp/BGPServer.java b/src/main/java/com/lumaserv/bgp/BGPServer.java index 53f8af7..265b138 100644 --- a/src/main/java/com/lumaserv/bgp/BGPServer.java +++ b/src/main/java/com/lumaserv/bgp/BGPServer.java @@ -26,6 +26,10 @@ public class BGPServer implements Runnable { serverSocket = new ServerSocket(port); } + public BGPServer(ServerSocket serverSocket) { + this.serverSocket = serverSocket; + } + private static boolean checkEqual(byte[] a, byte[] b) { if(a == b) return true; diff --git a/src/main/java/com/lumaserv/bgp/BGPSession.java b/src/main/java/com/lumaserv/bgp/BGPSession.java index dd2b7ff..bd40c13 100644 --- a/src/main/java/com/lumaserv/bgp/BGPSession.java +++ b/src/main/java/com/lumaserv/bgp/BGPSession.java @@ -204,17 +204,17 @@ System.out.println("Sent open"); if (socket == null) { while (true) { try { - System.out.println("Outgoing"); - socket = new Socket(); - socket.connect(new InetSocketAddress(host, port)); + System.out.println("Outgoing: " + host + ":" + port); + socket = configuration.getSocketFactory().createSocket(host, port); break; } catch(IOException ex) { + System.out.println("Exception: " + ex); if (closed) { throw new IOException("Closed", ex); } } } - System.out.println("Outgoing accepted"); + System.out.println("Outgoing accepted: " + socket.isConnected()); inputStream = socket.getInputStream(); outputStream = socket.getOutputStream(); fsm.getCurrentState().tcpCRAcked(); diff --git a/src/main/java/com/lumaserv/bgp/BGPSessionConfiguration.java b/src/main/java/com/lumaserv/bgp/BGPSessionConfiguration.java index 9c24d0a..2c76615 100644 --- a/src/main/java/com/lumaserv/bgp/BGPSessionConfiguration.java +++ b/src/main/java/com/lumaserv/bgp/BGPSessionConfiguration.java @@ -6,6 +6,8 @@ import lombok.Setter; import java.net.InetAddress; +import javax.net.SocketFactory; + @AllArgsConstructor @Setter @Getter @@ -17,5 +19,6 @@ public class BGPSessionConfiguration { int remoteAs; byte[] remoteIdentifier; InetAddress remoteAddr; + SocketFactory socketFactory; BGPListener listener; } |