-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9163a04
commit 4d7646b
Showing
3 changed files
with
57 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import asyncio | ||
from typing import Callable, Union | ||
from deccom.peers.peer import Peer | ||
from deccom.protocols.abstractprotocol import AbstractProtocol | ||
from deccom.protocols.streamprotocol import StreamProtocol | ||
from deccom.protocols.wrappers import bindfrom, bindto | ||
from deccom.utils.common import * | ||
|
||
class DelayProtocol(AbstractProtocol): | ||
def __init__(self, delay_map, submodule=None, callback: Callable[[tuple[str, int], bytes], None] = ...): | ||
self.stream_callback = lambda data, node_id,addr: ... | ||
self.delay_map = delay_map | ||
super().__init__(submodule, callback) | ||
|
||
@bindfrom("stream_callback") | ||
def process_data(self,data,node_id,addr): | ||
p = self.get_peer(node_id) | ||
loop = asyncio.get_event_loop() | ||
dl = self.delay_map(p.pub_key, self.peer.pub_key) | ||
|
||
loop.call_later(dl[0]/1000 + len(data)/(1024*1024*dl[1]), self.stream_callback, data, node_id, addr) | ||
#self.stream_callback(data,node_id,addr) | ||
|
||
|
||
@bindto("get_peer") | ||
def get_peer(self, id: bytes) -> Union[Peer,None]: | ||
return None |
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 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