-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove old VDE2 version, add rate-limiting
- Loading branch information
1 parent
3285187
commit 9149767
Showing
4 changed files
with
79 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
#WebSockets Proxy | ||
|
||
This is two different Python WebSockets servers which handle sending/receivng | ||
ethernet frames. tuntapapp.py works with TAP devices (creates one device per | ||
connection) and vdeapp.py connects to a VDE2 switch. Both are written using | ||
Tornado's awesome websocket server support. | ||
A virtual ethernet switch built using Tornado in Python | ||
|
||
Please note that these aren't super awesome, super configurable productioni | ||
ready services. These are just two quick hacks I put together to set up a demo. | ||
|
||
Also, to use vdeapp.py, make sure you've built VDE2 from source and installed | ||
the python bindings in order to enable VdePlug. | ||
Accepts ethernet frames via a WebSocket, or an ethernet TAP device. | ||
Rate limits WebSocket connections to prevent abuse. Could use some cleaning! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import time | ||
|
||
class RateLimitingState(object): | ||
def __init__(self, rate, clientip, name): | ||
self.name = name | ||
self.clientip = clientip | ||
self.rate = rate | ||
self.allowance = rate | ||
self.last_check = time.time() | ||
|
||
def do_throttle(self, message): | ||
current = time.time() | ||
time_passed = current - self.last_check | ||
|
||
self.last_check = current | ||
self.allowance += time_passed * self.rate | ||
|
||
if self.allowance > self.rate: | ||
self.allowance = self.rate #throttle | ||
|
||
if self.allowance > 1.0: | ||
self.allowance -= len(message) | ||
return True; | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.