harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Qiu" <sean.xx....@gmail.com>
Subject Re: [classlib]The bind operation of socket with SOCKS proxy
Date Tue, 09 Jan 2007 09:17:48 GMT
 public void test_bindLjava_net_SocketAddress_Proxy() throws IOException {
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("", 1080));
Socket socket = new Socket(proxy);

try {
InetAddress address = InetAddress.getByName("localhost");
int port = 22323;
socket.bind(new InetSocketAddress(address, port));
assertEquals(address, socket.getLocalAddress());
assertEquals(port, socket.getLocalPort());

} finally {
socket.close();
}
}

There is no proxy server at all.
This operation can be successfuly performed in RI but failed in Harmony.
It indicates that the bind will not connect to the SOCKS server.
So it should not invoke socksBind() which will connect and interact with the
SOCKS server.
I will apply a patch soon. :)

2007/1/9, Andrew Zhang <zhanghuangzhu@gmail.com>:
>
> On 1/9/07, Sean Qiu <sean.xx.qiu@gmail.com> wrote:
> >
> > The problem is  the socksBind() has little relationship with bind();
> > IMHO, it should not appear in bind() at all.
>
>
> Please test it when it connects to the socks server, and remove
> socksBind()
> if it has nothing to do with bind. :-)
>
> Correct me if i was wrong.  :)
>
>
> If you know you're right, you must have written test to prove your idea.
> why not post it here? :)
>
> 2007/1/8, Andrew Zhang <zhanghuangzhu@gmail.com>:
> > >
> > > On 1/8/07, Sean Qiu <sean.xx.qiu@gmail.com> wrote:
> > >
> > > > I mean that we remove both condition test about whether it uses a
> > SOCKS
> > > > proxy to construct a socket.
> > > > Because whether a socket is or not using a SOCKS
> > > > proxy, the bind operation is the same.
> > > >
> > > > But i am still not quite sure about it, so the patch is not
> available
> > > yet.
> > > > The modification of the patch may look like:
> > > >
> > > > [1]java.net.Socket
> > > >
> > > > public void bind(SocketAddress localAddr) throws IOException {
> > > > ...
> > > >
> > > > //if (!NetUtil.usingSocks(proxy)) {
> > > > impl.bind(addr, port);
> > > > //}
> > > >
> > > > ...
> > > > }
> > >
> > >
> > > The original code above (without your fix) seems self-contradictory.
> > > Because PlainSocketImpl.bind starts as follow:
> > > if (NetUtil.usingSocks(proxy)) {
> > >             socksBind();
> > >             return;
> > >         }
> > >
> > > How could that happen if we have "if (!NetUtil.usingSocks(proxy))"
> > > statement
> > > before binding  ;)
> > >
> > >
> > > > [2]org.apache.harmony.luni.net.PlainSocketImpl
> > > >
> > > > protected void bind(InetAddress anAddr, int aPort) throws
> IOException
> > {
> > > > //if (NetUtil.usingSocks (proxy)) {
> > > > //socksBind();
> > > > //return;
> > > > //}
> > >
> > >
> > > My feeling is that if test shows it should be binded, then we should
> > bind
> > > it
> > > first and then do socksBind() which connects to socks server, which
> > means
> > > to
> > > put "socksBind()" at the end of this method.  But I didn't write a
> test
> > > to verify my thought yet. :-)
> > >
> > >
> > > > It can pass the test.
> > > > But i am not sure it is the most appropriate way.
> > > > Thank you for any suggestion.   :)
> > > >
> > > > 2007/1/8, Andrew Zhang <zhanghuangzhu@gmail.com>:
> > > > >
> > > > > On 1/8/07, Sean Qiu <sean.xx.qiu@gmail.com> wrote:
> > > > > >
> > > > > > In [1], the code means that if constructs a new Socket with
> Socks
> > > > > proxy,it
> > > > > > will not bind the address at all.So the address and port will
> > remain
> > > > 0.
> > > > > > It causes the failure which was described in jira 2930 [2].So
> the
> > > > > > impl.bind(addr,port)
> > > > > > should be called to keep compatible with RI.
> > > > > >
> > > > > > But in [3], the method will call the socksBind() method which
is
> > > used
> > > > to
> > > > > > implement the BIND request in SOCKS protocol.
> > > > > >
> > > > > > According to RFC 1928 [4], it said that "The BIND request is
> used
> > in
> > > > > > protocols which require the client to accept connections from
> the
> > > > > > server.Itis expected that the client side of an application
> > protocol
> > > > > > will use the
> > > > > > BIND request only to establish secondary connections after a
> > primary
> > > > > > connection is established using CONNECT."
> > > > > > Obviously, this "BIND" in SOCKS Protocol is quite different
from
> > the
> > > > > > java.net.Socket.bind(SocketAddress) method.
> > > > > >
> > > > > > So in order to fix the bug, shall we remove both the condition
> > test?
> > > > >
> > > > >
> > > > > Hi Sean, what does "test" here mean? Do you mean the if statement
> or
> > > > test
> > > > > cases?
> > > > >
> > > > > or could you please provide the patch so that it's easy for
> > > discussing?
> > > > >
> > > > > Is my
> > > > > > thought wrong?
> > > > > > Thoughts? Concerns?Comments? Thanks.:)
> > > > > >
> > > > > >
> > > > > > [1] //java.net.Socket
> > > > > > public void bind(SocketAddress localAddr) throws IOException
{
> > > > > > ...
> > > > > > if (!NetUtil.usingSocks(proxy)) {
> > > > > > impl.bind(addr, port);
> > > > > > }
> > > > > > ...
> > > > > > }
> > > > > >
> > > > > > [2] http://issues.apache.org/jira/browse/HARMONY-2930
> > > > > >
> > > > > > [3] //org.apache.harmony.luni.net.PlainSocketImpl
> > > > > > protected void bind(InetAddress anAddr, int aPort) throws
> > > IOException
> > > > {
> > > > > > if (NetUtil.usingSocks(proxy)) {
> > > > > > socksBind();
> > > > > > return;
> > > > > > }
> > > > > > ...
> > > > > >
> > > > > > [4] http://rfc.net/rfc1928.html
> > > > > >
> > > > > > --
> > > > > > Sean Qiu
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Best regards,
> > > > > Andrew Zhang
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Sean Qiu
> > > >
> > > >
> > >
> > >
> > > --
> > > Best regards,
> > > Andrew Zhang
> > >
> > >
> >
> >
> > --
> > Sean Qiu
> >
> >
>
>
> --
> Best regards,
> Andrew Zhang
>
>


-- 
Sean Qiu

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message