-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: urcd
action: commit
revision:
path_from:
revision_from: c991fa11ff171f021edc089016b2d8cb6412901b:
path_to:
revision_to:

git.thebackupbox.net

urcd

git://git.thebackupbox.net/urcd

commit c991fa11ff171f021edc089016b2d8cb6412901b
Author: root <root@d3v11.ano>
Date:   Fri Feb 15 06:00:01 2013 +0000

    [URC] limit 1kb/s per connect (inbound)

diff --git a/src/urc2sd.pyx b/src/urc2sd.pyx

index 95cfd279d4291b4e6ae0da7d22d7bd323429a161..

index ..0378ce84ff0b3912582c115f7fa6f08b051158cb 100644

--- a/src/urc2sd.pyx
+++ b/src/urc2sd.pyx
@@ -12,9 +12,10 @@ import sys
 import re
 import os

-user = str(os.getpid())
-RE   = 'a-zA-Z0-9^(\)\-_{\}[\]|'
-nick = open('nick','rb').read().split('\n')[0]
+LIMIT = 1
+user  = str(os.getpid())
+RE    = 'a-zA-Z0-9^(\)\-_{\}[\]|'
+nick  = open('nick','rb').read().split('\n')[0]

 channels = collections.deque([],64)
 for dst in open('channels','rb').read().split('\n'):
@@ -69,13 +70,21 @@ client_POLLIN.register(rd,3)
 server_POLLIN=select.poll()
 server_POLLIN.register(sd,3)

+now = time.time()
+def limit():
+  if ((time.time() - now) > LIMIT):
+    global now
+    now = time.time()
+    return 0
+  return 1
+
 def client_poll():
-  return len( client_POLLIN.poll(256-
+  return 0 if limit() else len( client_POLLIN.poll(256-
     (256*len( server_POLLIN.poll(0)))
   ))

 def server_poll():
-  return len( server_POLLIN.poll(256-
+  return 0 if limit() else len( server_POLLIN.poll(256-
     (256*len( client_POLLIN.poll(0)))
   ))

diff --git a/src/urcd.pyx b/src/urcd.pyx

index 41788008df3febf5562558e7218269c1e36f0f7a..

index ..6710625159a083df81a6b268899eae65983c8ba7 100644

--- a/src/urcd.pyx
+++ b/src/urcd.pyx
@@ -12,6 +12,7 @@ import sys
 import re
 import os

+LIMIT      = 1
 NICKLEN    = 32
 TOPICLEN   = 512
 CHANLIMIT  = 64
@@ -68,8 +69,16 @@ client_POLLIN.register(rd,3)
 server_POLLIN=select.poll()
 server_POLLIN.register(sd,3)

+now = time.time()
+def limit():
+  if ((time.time() - now) > LIMIT):
+    global now
+    now = time.time()
+    return 0
+  return 1
+
 def client_poll():
-  return len( client_POLLIN.poll(256-
+  return 0 if limit() else len( client_POLLIN.poll(256-
     (256*len( server_POLLIN.poll(0)))
   ))

diff --git a/src/urcrecv.pyx b/src/urcrecv.pyx

index d0abfec15f8e0661a52c24ba51934fbf61c981e1..

index ..d938d95f1c535fc1fcfb31f7fefa8109978a537b 100644

--- a/src/urcrecv.pyx
+++ b/src/urcrecv.pyx
@@ -1,9 +1,12 @@
 #!/usr/bin/env python
 import socket
+import time
 import pwd
 import sys
 import os

+LIMIT = 1
+
 uid = pwd.getpwnam('urcd')[2]
 os.chdir(sys.argv[1])
 os.chroot(os.getcwd())
@@ -25,6 +28,8 @@ while 1:
     if byte == '\n':
       break

+  time.sleep(LIMIT)
+
   for path in os.listdir(root):
     try:
       sock.sendto(buffer,path)
diff --git a/src/urcstream.pyx b/src/urcstream.pyx

index aaa89a83c2dfc480151e9b3c764c9e33bbdd3e5b..

index ..7cea13cdc3d1cf3c0ae65461bfd343b68a5455de 100644

--- a/src/urcstream.pyx
+++ b/src/urcstream.pyx
@@ -2,11 +2,13 @@
 import socket
 import select
 import signal
+import time
 import pwd
 import sys
 import os

-user = str(os.getpid())
+user  = str(os.getpid())
+LIMIT = 1

 wr = 1
 if int(os.getenv('TCPCLIENT',0)):
@@ -44,8 +46,16 @@ client_POLLIN.register(rd,3)
 server_POLLIN=select.poll()
 server_POLLIN.register(sd,3)

+now = time.time()
+def limit():
+  if ((time.time() - now) > LIMIT):
+    global now
+    now = time.time()
+    return 0
+  return 1
+
 def client_poll():
-  return len( client_POLLIN.poll(256-
+  return 0 if limit() else len( client_POLLIN.poll(256-
     (256*len( server_POLLIN.poll(0)))
   ))

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 18:23:37 2024