final InetSocketAddress target,
Map reply )
{
if ( closed ){
reportFailed( new MessageException( "Connection has been closed" ));
}else{
connect_method_count++;
if ( TEST_TUNNEL ){
initial_data.rewind();
connectTunnel( initial_data, gen_udp, rendezvous, target );
}else{
udp_delegate.connect(
initial_data,
new GenericMessageConnectionAdapter.ConnectionListener()
{
private boolean connected;
public void
connectSuccess()
{
connected = true;
setDelegate( udp_delegate );
if ( closed ){
try{
delegate.close();
}catch( Throwable e ){
}
reportFailed( new MessageException( "Connection has been closed" ));
}else{
reportConnected();
}
}
public void
connectFailure(
Throwable failure_msg )
{
if ( connected ){
reportFailed( failure_msg );
}else{
initial_data.rewind();
connectTunnel( initial_data, gen_udp, rendezvous, target );
}
}
});
}
}
}
public void
failed(
int failure_type )
{
reportFailed( new MessageException( "UDP connection attempt failed - NAT traversal failed (" + NATTraversalObserver.FT_STRINGS[ failure_type ] + ")"));
}
public void
failed(
Throwable cause )
{
reportFailed( cause );
}
public void
disabled()
{
reportFailed( new MessageException( "UDP connection attempt failed as DDB is disabled" ));
}
});
}else{
udp_delegate.connect(
initial_data,
new GenericMessageConnectionAdapter.ConnectionListener()
{
private boolean connected;
public void
connectSuccess()
{
connected = true;
setDelegate( udp_delegate );
if ( closed ){
try{
delegate.close();
}catch( Throwable e ){
}
reportFailed( new MessageException( "Connection has been closed" ));
}else{
reportConnected();
}