-
Proxy Service Issues
From
Drakmir@VERT/HDONE to
All on Thu Oct 6 09:44:00 2005
I am trying to write a simple socket proxy in Synchronet's Javascript language,ãand having a very hard time of it. The code below is my latest attempt, butãI've tried many variations on that theme (including blocking sockets, usingãsend/receive buffers, etc).ã ãAll of them either result in a crash in the services module or a lockup of allãnetworking (including non synchronet) on the computer. I'm running withãSynchronet 3.12 and on Win2k.ã ãCan someone assist with this and tell me what I'm doing wrong? ã ãThanks!ã ãCode follows.ããAlan Woodã ã----- CODE ------ã ãload("sockdefs.js");ããfunction CopyData(socketA, socketB)ã{ã if (socketA.poll())ã {ã if (socketB.poll(0, true))ã {ã var nBytes = socketA.nread;ã var readVal = socketA.recvBin(1);ã ã if ((readVal > 0) && (socketA.error == 0))ã {ã if (!socketB.sendBin(readVal, 1))ã {ã throw ("Error writing to socket");ã }ã }ã }ã }ã}ããtryã{ã if (argc < 2)ã {ã throw("No parameters passed.");ã };ã ã var proxySocket = new Socket(SOCK_STREAM);ã proxySocket.nonblocking = 1;ã client.socket.nonblocking = 1;ã ã if (proxySocket.connect(argv[0], argv[1]))ã {ã while((client.socket.is_connected) && (proxySocket.is_connected) &&ã(!proxySocket.error) && (!client.socket.error))ã {ã CopyData(client.socket, proxySocket);ã yield();ã ã CopyData(proxySocket, client.socket);ã yield();ã }ã ã proxySocket.close();ã }ã elseã {ã throw("Error connecting to proxied socket.");ã }ã}ãcatch(E)ã{ã log("Caught error - " + E);ã exit(-1);ã}ããexit(0);ãã---ã þ Synchronet þ Holodeck One - bbs.holodeckone.comã
-
From
Digital Man@VERT to
Drakmir on Thu Oct 6 18:44:45 2005
Re: Proxy Service Issuesã By: Drakmir to All on Thu Oct 06 2005 09:44 amãã > I am trying to write a simple socket proxy in Synchronet's Javascript languaã > and having a very hard time of it. The code below is my latest attempt, butã > I've tried many variations on that theme (including blocking sockets, usingã > send/receive buffers, etc).ã > ã > All of them either result in a crash in the services module or a lockup of aã > networking (including non synchronet) on the computer. I'm running withã > Synchronet 3.12 and on Win2k.ããI tried your script (using the ;EXEC sysop command to just loop back toãlocalhost, port 23) and it was able to receive okay, but slowing, it wasn'tãable to send. There was no crashing or lockups anything.ããI'll have to play with it later. Have you seen exec/socktest.js? It does veryãmuch what you're trying to, but faster (transmits and receives in blocks) andãworks for both transmit and receive. I think it's a pretty simple example.ãã digital manããSnapple "Real Fact" #11:ãFlamingos are pink because they eat shrimp.ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
Drakmir@VERT/HDONE to
Digital Man on Fri Oct 7 00:25:00 2005
Re: Proxy Service Issuesã By: Digital Man to Drakmir on Thu Oct 06 2005 07:44 pmããI hadn't seen that one. I'll take a look at it and see if it works for myãapplication. :)ã ãThat proxy is slow because I removed block read/write since I wasn't sure whatãwas going wrong. It was the simpliest example I could get to fail and not takeãdown the computer with it. ã ãThanks again!ã ãAlanãã---ã þ Synchronet þ Holodeck One - bbs.holodeckone.comã
-
From
Drakmir@VERT/HDONE to
Digital Man on Fri Oct 7 00:38:00 2005
Re: Proxy Service Issuesã By: Drakmir to Digital Man on Thu Oct 06 2005 11:25 pmãã > Re: Proxy Service Issuesã > By: Digital Man to Drakmir on Thu Oct 06 2005 07:44 pmã > ã > I hadn't seen that one. I'll take a look at it and see if it works for myã > application. :)ã > ã > That proxy is slow because I removed block read/write since I wasn't sure whã > was going wrong. It was the simpliest example I could get to fail and not tã > down the computer with it.ã > ã > Thanks again!ã > ã > AlanãSo, I adapted socktest to read from client.socket instead of console, and forãsome reason it won't read the input. I basically just changed the RAW modeãinkey for the same if logic above (client.socket.data_waiting).ã ãIs there a socket option that has to be set or something?ã ãAlanãã---ã þ Synchronet þ Holodeck One - bbs.holodeckone.comã
-
From
Drakmir@VERT/HDONE to
Digital Man on Fri Oct 7 00:50:00 2005
Re: Proxy Service Issuesã By: Drakmir to Digital Man on Thu Oct 06 2005 11:38 pmãã > Re: Proxy Service Issuesã > By: Drakmir to Digital Man on Thu Oct 06 2005 11:25 pmã > ã > > Re: Proxy Service Issuesã > > By: Digital Man to Drakmir on Thu Oct 06 2005 07:44 pmã > >ã > > I hadn't seen that one. I'll take a look at it and see if it works for mã > > application. :)ã > >ã > > That proxy is slow because I removed block read/write since I wasn't sureã > > was going wrong. It was the simpliest example I could get to fail and noã > > down the computer with it.ã > >ã > > Thanks again!ã > >ã > > Alanã > So, I adapted socktest to read from client.socket instead of console, and foã > some reason it won't read the input. I basically just changed the RAW modeã > inkey for the same if logic above (client.socket.data_waiting).ã > ã > Is there a socket option that has to be set or something?ã > ã > AlanãThe following code has the issue above (no read of the client socket for someãreason):ã ã while(socket.is_connected && client.socket.is_connected) ã {ã if(socket.data_waiting) ã {ã buf = socket.read();ã client.socket.write(buf);ã continue;ã }ãã if(client.socket.data_waiting)ã {ã buf = client.socket.read();ã socket.write(buf);ã continue;ã }ã sleep(1);ã }ããChanging it to:ã ã while(socket.is_connected && client.socket.is_connected) ã {ã if(socket.data_waiting) ã {ã buf = socket.readBin(1);ã client.socket.writeBin(buf, 1);ã continue;ã }ãã if(client.socket.data_waiting)ã {ã buf = client.socket.readBin(1);ã socket.writeBin(buf, 1);ã continue;ã }ã sleep(1);ã }ããCauses the crash condition. I know I switched to readBin/writeBin when I hadãproblems with read/write interpreting something I didn't want it to interpret. ãNot sure of the specifics anymore, so I'll try with read/write again some moreãto see if I can figure out a combination that allows for both read and write.ã ãAlanãã---ã þ Synchronet þ Holodeck One - bbs.holodeckone.comã
-
From
Drakmir@VERT/HDONE to
Digital Man on Fri Oct 7 01:25:00 2005
Re: Proxy Service Issuesã By: Drakmir to Digital Man on Thu Oct 06 2005 11:50 pmããI think I have a solution, although the problem is interesting. ã ãI changed the read code to be the following:ã ã if(socket.data_waiting) ã {ã var numRead = socket.nread;ã buf = socket.read();ã if (numRead != buf.length)ã {ã log("2 - " + numRead + " vs. " + buf.length);ã }ã client.socket.write(buf);ã continue;ã }ã sleep(1);ããAnd noticed that the string being returned from "read" had the wrong number ofãbytes occasionally. I assume there are embedded \0 characters in the telnetãresponses?ã ãAnyway, switching to the following read code seems to help:ã ã if(client.socket.data_waiting)ã {ã var numRead = client.socket.nread;ã if (numRead >= 512) numRead = 512;ã ã while(numRead > 4)ã {ã buf = client.socket.recvBin(4);ã socket.sendBin(buf, 4);ã numRead -= 4;ã }ã ã if (numRead > 0)ã {ã buf = client.socket.recvBin(numRead);ã socket.sendBin(buf, numRead);ã }ã continue;ã }ããI'll see if that has any weird effects.ã ãI'm signing off now.ã ãAlanãã---ã þ Synchronet þ Holodeck One - bbs.holodeckone.comã
-
From
Digital Man@VERT to
Drakmir on Thu Oct 6 22:27:27 2005
Re: Proxy Service Issuesã By: Drakmir to Digital Man on Fri Oct 07 2005 12:38 amãã > Re: Proxy Service Issuesã > By: Drakmir to Digital Man on Thu Oct 06 2005 11:25 pmã > ã > > Re: Proxy Service Issuesã > > By: Digital Man to Drakmir on Thu Oct 06 2005 07:44 pmã > >ã > > I hadn't seen that one. I'll take a look at it and see if it works for mã > > application. :)ã > >ã > > That proxy is slow because I removed block read/write since I wasn't sureã > > was going wrong. It was the simpliest example I could get to fail and noã > > down the computer with it.ã > >ã > > Thanks again!ãã > So, I adapted socktest to read from client.socket instead of console, and foã > some reason it won't read the input. I basically just changed the RAW modeã > inkey for the same if logic above (client.socket.data_waiting).ã > ã > Is there a socket option that has to be set or something?ããYes, you can't perform I/O on the client's socket descriptor while the BBS'sãinput thread is servicing the socking. You must set console.lock_input to trueãbefore accessing the client's socket directly and set it to to false whenãyou're done.ãã digital manããSnapple "Real Fact" #12:ãEmus and Kangaroos cannot walk backwards.ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
Drakmir@VERT/HDONE to
Digital Man on Fri Oct 7 09:46:00 2005
Re: Proxy Service Issuesã By: Digital Man to Drakmir on Thu Oct 06 2005 11:27 pmãã > Re: Proxy Service Issuesã > By: Drakmir to Digital Man on Fri Oct 07 2005 12:38 amã > ã > > Re: Proxy Service Issuesã > > By: Drakmir to Digital Man on Thu Oct 06 2005 11:25 pmã > >ã > > > Re: Proxy Service Issuesã > > > By: Digital Man to Drakmir on Thu Oct 06 2005 07:44 pmã > > >ã > > > I hadn't seen that one. I'll take a look at it and see if it works foã > > > application. :)ã > > >ã > > > That proxy is slow because I removed block read/write since I wasn't sã > > > was going wrong. It was the simpliest example I could get to fail andã > > > down the computer with it.ã > > >ã > > > Thanks again!ã > ã > > So, I adapted socktest to read from client.socket instead of console, andã > > some reason it won't read the input. I basically just changed the RAW moã > > inkey for the same if logic above (client.socket.data_waiting).ã > >ã > > Is there a socket option that has to be set or something?ã > ã > Yes, you can't perform I/O on the client's socket descriptor while the BBS'sã > input thread is servicing the socking. You must set console.lock_input to trã > before accessing the client's socket directly and set it to to false whenã > you're done.ã > ã > digital manã > ã > Snapple "Real Fact" #12:ã > Emus and Kangaroos cannot walk backwards.ã > ãThe problem with that is when you have a "service", the console object doesn'tãexist.ã ãAlanãã---ã þ Synchronet þ Holodeck One - bbs.holodeckone.comã
-
From
Drakmir@VERT/HDONE to
All on Fri Oct 7 09:56:00 2005
Re: Proxy Service Issuesã By: Drakmir to All on Thu Oct 06 2005 08:44 amããSo, after working on it last night and with some hints from Digital Man, I'veãcome up with something that seems to work to proxy a socket. There is only oneãunknown, and I've noticed that the use of "sendBin" seems to be what isãcrashing my computer. (If I use any number of bytes other that 4 it seems toãoccasionaly crash).ã ãThe one sticky point is that when using "peek" or "read", sometimes you get aãstring that is shorter than the number of bytes available to you. The onlyãthing I can think of is that there is a embedded \0 character in the dataãstream which C is then reading as the end of the string. It would help to haveãa read/write that dealt with the "string" we provide as a buffer instead. Iãassume this is true because doing:ããsocket.send("test\0test2"); only outputs "test".ã ãAlanãã-+- Code ---ãload("sockdefs.js"); ããfunction sendData(socketA, socketB)ã{ã var bRetVal = false;ã var buf;ã ã if(socketA.data_waiting)ã {ã var numRead = socketA.nread;ã if (numRead > 512) numRead = 512;ã buf = socketA.peek(numRead);ã ã if (numRead != buf.length)ã {ã numRead = buf.length;ã buf = socketA.recv(numRead + 1); // Not sure what we areãskipping here, but it seems harmless? Maybe a zero?ã socketB.send(buf);ã }ã elseã {ã buf = socketA.recv(numRead);ã socketB.send(buf);ã }ãã bRetVal = true;ã }ã ã return bRetVal;ã}ããtryã{ã if (argc < 2)ã {ã throw("No parameters passed.");ã };ãã var socket = new Socket();ã ã if(!socket.bind()) {ã throw("!bind error " + socket.last_error + "\r\n");ã exit();ã }ã ã var addr=argv[0];ã var port=argv[1];ã ã if(!socket.connect(addr,port)) {ã throw("!connect error " + socket.last_error + "\r\n");ã exit();ã }ã ã while(socket.is_connected && client.socket.is_connected) ã {ã if (sendData(socket, client.socket)) continue;ã if (sendData(client.socket, socket)) continue;ã sleep(1);ã }ã}ãcatch(E)ã{ã log("Caught error - " + E);ã exit(-1);ã}ããexit(0);ãã---ã þ Synchronet þ Holodeck One - bbs.holodeckone.comã
-
From
Digital Man@VERT to
Drakmir on Tue Oct 11 16:51:14 2005
Re: Proxy Service Issuesã By: Drakmir to Digital Man on Fri Oct 07 2005 09:46 amãã > Re: Proxy Service Issuesã > By: Digital Man to Drakmir on Thu Oct 06 2005 11:27 pmã > ã > > Re: Proxy Service Issuesã > > By: Drakmir to Digital Man on Fri Oct 07 2005 12:38 amã > >ã > > > Re: Proxy Service Issuesã > > > By: Drakmir to Digital Man on Thu Oct 06 2005 11:25 pmã > > >ã > > > > Re: Proxy Service Issuesã > > > > By: Digital Man to Drakmir on Thu Oct 06 2005 07:44 pmã > > > >ã > > > > I hadn't seen that one. I'll take a look at it and see if it worksã > > > > application. :)ã > > > >ã > > > > That proxy is slow because I removed block read/write since I wasn'ã > > > > was going wrong. It was the simpliest example I could get to fail ã > > > > down the computer with it.ã > > > >ã > > > > Thanks again!ã > >ã > > > So, I adapted socktest to read from client.socket instead of console, ã > > > some reason it won't read the input. I basically just changed the RAWã > > > inkey for the same if logic above (client.socket.data_waiting).ã > > >ã > > > Is there a socket option that has to be set or something?ã > >ã > > Yes, you can't perform I/O on the client's socket descriptor while the BBã > > input thread is servicing the socking. You must set console.lock_input toã > > before accessing the client's socket directly and set it to to false whenã > > you're done.ãã > The problem with that is when you have a "service", the console object doesnã > exist.ããWhen run as a service, there is not "input_thread" (the service is expected toãinteract with the socket directly), so the locking is not necessary.ãã digital manããSnapple "Real Fact" #90:ãThe average raindrop falls at 7mph.ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
Digital Man@VERT to
Drakmir on Tue Oct 11 17:18:55 2005
Re: Proxy Service Issuesã By: Drakmir to All on Fri Oct 07 2005 09:56 amãã > Re: Proxy Service Issuesã > By: Drakmir to All on Thu Oct 06 2005 08:44 amã > ã > So, after working on it last night and with some hints from Digital Man, I'vã > come up with something that seems to work to proxy a socket. There is only oã > unknown, and I've noticed that the use of "sendBin" seems to be what isã > crashing my computer. (If I use any number of bytes other that 4 it seems tã > occasionaly crash).ããWhat value (for number of byte) did you use when it crashed? Do you haveãexample code that can reproduce this crash?ãã > The one sticky point is that when using "peek" or "read", sometimes you get ã > string that is shorter than the number of bytes available to you. The onlyã > thing I can think of is that there is a embedded \0 character in the dataã > stream which C is then reading as the end of the string. It would help to hã > a read/write that dealt with the "string" we provide as a buffer instead. Iã > assume this is true because doing:ã > ã > socket.send("test\0test2"); only outputs "test".ããAh, true. That'll be fixed for the next release. :-)ãã digital manããSnapple "Real Fact" #8:ãA bee has 5 eyes.ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
Drakmir@VERT/HDONE to
Digital Man on Fri Oct 14 11:35:00 2005
Re: Proxy Service Issuesã By: Digital Man to Drakmir on Tue Oct 11 2005 06:18 pmãã > Re: Proxy Service Issuesã > By: Drakmir to All on Fri Oct 07 2005 09:56 amã > ã > > Re: Proxy Service Issuesã > > By: Drakmir to All on Thu Oct 06 2005 08:44 amã > >ã > > So, after working on it last night and with some hints from Digital Man, ã > > come up with something that seems to work to proxy a socket. There is onlã > > unknown, and I've noticed that the use of "sendBin" seems to be what isã > > crashing my computer. (If I use any number of bytes other that 4 it seemã > > occasionaly crash).ã > ã > What value (for number of byte) did you use when it crashed? Do you haveã > example code that can reproduce this crash?ã > ã > > The one sticky point is that when using "peek" or "read", sometimes you gã > > string that is shorter than the number of bytes available to you. The onã > > thing I can think of is that there is a embedded \0 character in the dataã > > stream which C is then reading as the end of the string. It would help tã > > a read/write that dealt with the "string" we provide as a buffer instead.ã > > assume this is true because doing:ã > >ã > > socket.send("test\0test2"); only outputs "test".ã > ã > Ah, true. That'll be fixed for the next release. :-)ã > ã > digital manã > ã > Snapple "Real Fact" #8:ã > A bee has 5 eyes.ã > ãThanks! That should do it for me.ã ãI've changed the proxy code and TWGSRobotCode to send the byte, and over theãpast 3 days I've had no lockups. So, even though it was crashing usingã"sendBin(0, 1)" (since commenting out that code made the crash go away), Iãdon't think it was that in particular. Maybe something that I was doing aroundãit made that function fail dramatically? ã ãAnyway, the new proxy code sends the zero bytes now. I don't have an exampleãto send you digital man, but if I get around to trying to recreate the crashes,ãI'll send it in. :)ã ãThanks again for your help!ã ãAlanãã---ã þ Synchronet þ Holodeck One - bbs.holodeckone.comã