JuliaLang / MbedTLS.jl

Wrapper around mbedtls
Other
41 stars 50 forks source link

Delay after initial write #236

Open cfitz25 opened 3 years ago

cfitz25 commented 3 years ago

Hello, i seem to be getting a delay whenever i write a second time to an encrypted connection. Any ideas why this would be happening? I think it is something to do with either the write not actually sending immediately or the read not receiving fast enough

Julia Version 1.6.1
Commit 6aaedecc44* (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.1.0 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 4
  JULIA_DEBUG = all
Server
using Sockets
using MbedTLS
server = Sockets.listen(8080)

conn = accept(server)
entropy = MbedTLS.Entropy()
rng = MbedTLS.CtrDrbg()
MbedTLS.seed!(rng, entropy)
ctx = MbedTLS.SSLContext()
conf = MbedTLS.SSLConfig("selfsigned.cert", "selfsigned.key")

# MbedTLS.config_defaults!(conf)
MbedTLS.authmode!(conf, MbedTLS.MBEDTLS_SSL_VERIFY_NONE)
MbedTLS.rng!(conf, rng)
MbedTLS.ca_chain!(conf)
MbedTLS.setup!(ctx, conf)
MbedTLS.associate!(ctx, conn)
MbedTLS.handshake(ctx)   

while(true)
    data = readavailable(ctx)
    sleep(0.01)

    if(length(data) == 0)
        continue
    end
    println(data)
    write(ctx,data)
    flush(ctx)
end

client

using Sockets
using MbedTLS
client=Sockets.connect(8080)
entropy = MbedTLS.Entropy()
rng = MbedTLS.CtrDrbg()
MbedTLS.seed!(rng, entropy)
ctx = MbedTLS.SSLContext()
conf = MbedTLS.SSLConfig()
MbedTLS.config_defaults!(conf)
MbedTLS.authmode!(conf, MbedTLS.MBEDTLS_SSL_VERIFY_NONE)
MbedTLS.rng!(conf, rng)

function show_debug(level, filename, number, msg)
    println((level, filename, number, msg))
    # println(msg)
end

MbedTLS.dbg!(conf, show_debug)
MbedTLS.set_dbg_level(MbedTLS.ERROR)
MbedTLS.ca_chain!(conf)
MbedTLS.setup!(ctx, conf)
MbedTLS.set_bio!(ctx, client)
MbedTLS.handshake(ctx)

while(true)
    write(ctx,UInt8[1,1,1,1,1,1,1,1,1,1,1,1])
    flush(ctx)
    data = []
    while(true)
        data = readavailable(ctx)
        if(length(data) > 0)
            break
        end
        sleep(0.1)
    end
    println(data)

end