Authentication in server protocol

Wednesday, 8 December 2021 · 3 messages
BE
Ben Engbers8 Dec 2021 12:53 #
Hi Christian, All my previous packages for RBaseX were based on using a blocking socket. Every attempt to use a non-blocking socket failed because I couldn't authenticate. In R each read-operation on a blocking socket uses a timeout of at least 1 second. Consequence was that executing 53 tests on my pacakge took at least 116 seconds on my machine. I finally managed to use a non-blocking socket. Execution of the same tests now take 3.8 seconds. It showed that the crucial needed step was to introduce a sleep/wait between sending the authentication nonce and checking the statusbyte: code <- md5(paste(md5(code), nonce, sep = "")) %>% charToRaw() # send username + code auth <- c(charToRaw(username), as.raw(0x00), code, as.raw(0x00)) writeBin(auth, private$conn) ==> Sys.sleep(.1) Accepted <- readBin(conn, what = "raw", n = 1) ==0 My knowledge of working with sockets is limited so maybe you can answer my question. Does the need of using a sleep means I need to fix a bug in the R code or should I use a setting in BaseX that takes into account the required delay? Ben Engbers
CG
Christian Grün8 Dec 2021 12:55 #
Hi Ben, I assume this challenge needs to be tackled in the R realm: If the Java client is used, no sleep is required at all. Hope this helps, Christian
Quoted text · Ben Engbers · 30 lines
On Wed, Dec 8, 2021 at 12:53 PM Ben Engbers <Ben.Engbers at be-logical.nl> wrote: > > Hi Christian, > > All my previous packages for RBaseX were based on using a blocking > socket. Every attempt to use a non-blocking socket failed because I > couldn't authenticate. > In R each read-operation on a blocking socket uses a timeout of at least > 1 second. Consequence was that executing 53 tests on my pacakge took at > least 116 seconds on my machine. > > I finally managed to use a non-blocking socket. Execution of the same > tests now take 3.8 seconds. > It showed that the crucial needed step was to introduce a sleep/wait > between sending the authentication nonce and checking the statusbyte: > > code <- md5(paste(md5(code), nonce, sep = "")) %>% charToRaw() > # send username + code > auth <- c(charToRaw(username), as.raw(0x00), code, as.raw(0x00)) > writeBin(auth, private$conn) > ==> Sys.sleep(.1) > Accepted <- readBin(conn, what = "raw", n = 1) ==0 > > My knowledge of working with sockets is limited so maybe you can answer > my question. > Does the need of using a sleep means I need to fix a bug in the R code > or should I use a setting in BaseX that takes into account the required > delay? > > Ben Engbers
BE
Ben Engbers8 Dec 2021 18:27 #
Hi Christian, As far as I now understand, a socketConnection is not a single connection but in fact a pool of connections. And I believe this is language-independent. In R, Tthe command socketSelect(list(<connection>)) waits for the first of several socket connections and server sockets to become available. After inserting this command in my code, there is no need anymore to explicitly insert a sleep. Execution-time for all the results has been reduced to 1.4 seconds instead of 120 as before. Now I can really start using RbaseX! Ben
Quoted text · Christian Grün · 8 lines
Op 08-12-2021 om 12:55 schreef Christian Grün: > Hi Ben, > > I assume this challenge needs to be tackled in the R realm: If the > Java client is used, no sleep is required at all. > > Hope this helps, > Christian

⚡Generated with XQuery