Skip to content

Commit

Permalink
remove proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ovv committed May 2, 2018
1 parent 717f0ff commit 2dd0ceb
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 209 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ async-timeout = "*"
[dev-packages]
twine = "*"
pytest-asyncio = "*"
"flake8" = "*"

[requires]
python_version = "3.6"
33 changes: 32 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions aiosip/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from collections import MutableMapping

from . import __version__
from .dialog import Dialog, ProxyDialog
from .dialog import Dialog
from .dialplan import BaseDialplan
from .protocol import UDP, TCP, WS
from .peers import UDPConnector, TCPConnector, WSConnector
Expand Down Expand Up @@ -128,17 +128,6 @@ async def prepare(self, status_code, *args, **kwargs):

return dialog

async def proxy(self, message, proxy_peer=None, dialog_factory=ProxyDialog):
if not proxy_peer:
proxy_peer = await self.app.connect(
remote_addr=(message.to_details.host, message.to_details.port),
protocol=peer.protocol
)

dialog = self._create_dialog(dialog_factory=dialog_factory, proxy_peer=proxy_peer)
dialog.proxy(message)
return dialog

request = Request()
await route(request, msg)

Expand Down
48 changes: 0 additions & 48 deletions aiosip/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,51 +447,3 @@ async def close(self, timeout=None):
self._close()

self._close()


class ProxyDialog(DialogBase):
def __init__(self, *args, proxy_peer, **kwargs):
super().__init__(*args, **kwargs)
self.proxy_peer = proxy_peer
self._incoming = asyncio.Queue()

@property
def dialog_id(self):
return frozenset((self.to_details['params']['tag'],
self.from_details['params'].get('tag'),
self.call_id))

async def receive_message(self, msg):
if 'tag' not in self.from_details['params'] and 'tag' in msg.to_details['params']:
del self.app._dialogs[self.dialog_id]
self.from_details['params']['tag'] = msg.to_details['params']['tag']
self.app._dialogs[self.dialog_id] = self

await self._incoming.put(msg)

async def recv(self):
return await self._incoming.get()

def proxy(self, message):
# TODO: should be cleaner
if not isinstance(message.headers['Via'], list):
message.headers['Via'] = [message.headers['Via'], ]

if f'{self.peer.peer_addr[0]}:{self.peer.peer_addr[1]}' in message.headers['Via'][0]:
message.headers['Via'].insert(0, self.proxy_peer.generate_via_headers())
self.proxy_peer.send_message(message)
elif f'{self.peer.local_addr[0]}:{self.peer.local_addr[1]}' in message.headers['Via'][0]:
message.headers['Via'].pop(0)
self.proxy_peer.send_message(message)
elif f'{self.proxy_peer.peer_addr[0]}:{self.proxy_peer.peer_addr[1]}' in message.headers['Via'][0]:
message.headers['Via'].insert(0, self.peer.generate_via_headers())
self.peer.send_message(message)
elif f'{self.proxy_peer.local_addr[0]}:{self.proxy_peer.local_addr[1]}' in message.headers['Via'][0]:
message.headers['Via'].pop(0)
self.peer.send_message(message)
else:
message.headers['Via'].insert(0, self.proxy_peer.generate_via_headers())
self.proxy_peer.send_message(message)

async def close(self, *args, **kwargs):
self._close()
5 changes: 2 additions & 3 deletions aiosip/peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import utils
from .contact import Contact
from .protocol import UDP, TCP, WS
from .dialog import Dialog, InviteDialog, ProxyDialog
from .dialog import Dialog, InviteDialog

LOG = logging.getLogger(__name__)

Expand All @@ -35,8 +35,7 @@ def send_message(self, msg):
def _create_dialog(self, method, from_details, to_details, contact_details=None, password=None, call_id=None,
headers=None, payload=None, cseq=0, inbound=False, dialog_factory=Dialog, **kwargs):

if not issubclass(dialog_factory, ProxyDialog):
from_details.add_tag()
from_details.add_tag()

if not call_id:
call_id = str(uuid.uuid4())
Expand Down
Loading

0 comments on commit 2dd0ceb

Please sign in to comment.