Skip to content

Commit

Permalink
Orchid: allow creation of unconnected socket
Browse files Browse the repository at this point in the history
  • Loading branch information
devrandom authored and mikehearn committed Apr 27, 2014
1 parent 99448b7 commit 23da335
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 11 additions & 5 deletions orchid/src/com/subgraph/orchid/sockets/OrchidSocketFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ public OrchidSocketFactory(TorClient torClient, boolean exceptionOnLocalBind) {
this.exceptionOnLocalBind = exceptionOnLocalBind;
}

@Override
@Override
public Socket createSocket() throws IOException {
return createSocketInstance();
}

@Override
public Socket createSocket(String host, int port) throws IOException,
UnknownHostException {
return createOrchidSocket(host, port);
final Socket s = createSocketInstance();
return connectOrchidSocket(s, host, port);
}

@Override
Expand All @@ -43,7 +49,8 @@ public Socket createSocket(String host, int port, InetAddress localHost,

@Override
public Socket createSocket(InetAddress address, int port) throws IOException {
return createOrchidSocket(address.getHostAddress(), port);
final Socket s = createSocketInstance();
return connectOrchidSocket(s, address.getHostAddress(), port);
}

@Override
Expand All @@ -55,8 +62,7 @@ public Socket createSocket(InetAddress address, int port,
return createSocket(address, port);
}

private Socket createOrchidSocket(String host, int port) throws IOException {
final Socket s = createSocketInstance();
private Socket connectOrchidSocket(Socket s, String host, int port) throws IOException {
final SocketAddress endpoint = InetSocketAddress.createUnresolved(host, port);
s.connect(endpoint);
return s;
Expand Down
9 changes: 6 additions & 3 deletions orchid/src/com/subgraph/orchid/sockets/OrchidSocketImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ protected void create(boolean stream) throws IOException {

@Override
protected void connect(String host, int port) throws IOException {
throw new UnsupportedOperationException();
SocketAddress endpoint =
InetSocketAddress.createUnresolved(host, port);
connect(endpoint, 0);
}

@Override
protected void connect(InetAddress address, int port) throws IOException {
throw new UnsupportedOperationException();

SocketAddress endpoint =
InetSocketAddress.createUnresolved(address.getHostAddress(), port);
connect(endpoint, 0);
}

@Override
Expand Down

0 comments on commit 23da335

Please sign in to comment.