78 module:log("debug", "target connected ... "); |
78 module:log("debug", "target connected ... "); |
79 elseif transfers[sha].target ~= nil then |
79 elseif transfers[sha].target ~= nil then |
80 transfers[sha].initiator = conn; |
80 transfers[sha].initiator = conn; |
81 session.sha = sha; |
81 session.sha = sha; |
82 module:log("debug", "initiator connected ... "); |
82 module:log("debug", "initiator connected ... "); |
|
83 throttle_sending(conn, transfers[sha].target); |
83 end |
84 end |
84 conn:write(string.char(5, 0, 0, 3, sha:len()) .. sha .. string.char(0, 0)); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte) |
85 conn:write(string.char(5, 0, 0, 3, sha:len()) .. sha .. string.char(0, 0)); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte) |
85 else |
86 else |
86 module:log("warn", "Neither data transfer nor initial connect of a participator of a transfer.") |
87 module:log("warn", "Neither data transfer nor initial connect of a participator of a transfer.") |
87 conn.close(); |
88 conn.close(); |
251 module:log("error", "Possibly two proxy65 components are configured to share the same port."); |
252 module:log("error", "Possibly two proxy65 components are configured to share the same port."); |
252 end |
253 end |
253 |
254 |
254 connlisteners.start(module.host .. ':proxy65'); |
255 connlisteners.start(module.host .. ':proxy65'); |
255 component = componentmanager.register_component(host, handle_to_domain); |
256 component = componentmanager.register_component(host, handle_to_domain); |
|
257 local sender_lock_threshold = 1024; |
|
258 function throttle_sending(sender, receiver) |
|
259 sender:pattern(sender_lock_threshold); |
|
260 local sender_locked; |
|
261 local _sendbuffer = receiver.sendbuffer; |
|
262 function receiver.sendbuffer() |
|
263 _sendbuffer(); |
|
264 if sender_locked and receiver.bufferlen() < sender_lock_threshold then |
|
265 sender:lock(false); -- Unlock now |
|
266 sender_locked = nil; |
|
267 end |
|
268 end |
|
269 |
|
270 local _readbuffer = sender.readbuffer; |
|
271 function sender.readbuffer() |
|
272 _readbuffer(); |
|
273 if not sender_locked and receiver.bufferlen() >= sender_lock_threshold then |
|
274 sender_locked = true; |
|
275 sender:lock(true); |
|
276 end |
|
277 end |
|
278 end |