Exemplo n.º 1
0
 def hostinfo_local(self):
     # `host` already contains the interface identifier, so throwing away
     # scope and interface identifier
     host, port, *_ = self._transport.get_extra_info('socket').getsockname()
     if port == self._ctx._default_port:
         port = None
     return util.hostportjoin(host, port)
Exemplo n.º 2
0
    async def _spawn_protocol(self, message):
        if message.unresolved_remote is None:
            host = message.opt.uri_host
            port = message.opt.uri_port or self._default_port
            if host is None:
                raise ValueError(
                    "No location found to send message to (neither in .opt.uri_host nor in .remote)"
                )
        else:
            host, port = util.hostportsplit(message.unresolved_remote)
            port = port or self._default_port

        if (host, port) in self._pool:
            return self._pool[(host, port)]

        try:
            _, protocol = await self.loop.create_connection(
                lambda: TcpConnection(self,
                                      self.log,
                                      self.loop,
                                      hostinfo=util.hostportjoin(host, port)),
                host,
                port,
                ssl=self._ssl_context_factory())
        except socket.gaierror:
            raise error.ResolutionError(
                "No address information found for requests to %r" % host)
        except OSError:
            raise error.NetworkError("Connection failed to %r" % host)

        self._pool[(host, port)] = protocol

        return protocol
Exemplo n.º 3
0
 def hostinfo_local(self):
     # `host` already contains the interface identifier, so throwing away
     # scope and interface identifier
     host, port, *_ = self._transport.get_extra_info('socket').getsockname()
     if port == self._ctx._default_port:
         port = None
     return util.hostportjoin(host, port)
Exemplo n.º 4
0
    async def _spawn_protocol(self, message):
        if message.unresolved_remote is None:
            host = message.opt.uri_host
            port = message.opt.uri_port or self._default_port
            if host is None:
                raise ValueError(
                    "No location found to send message to (neither in .opt.uri_host nor in .remote)"
                )
        else:
            host, port = util.hostportsplit(message.unresolved_remote)
            port = port or self._default_port

        if (host, port) in self._pool:
            return self._pool[(host, port)]

        _, protocol = await self.loop.create_connection(lambda: TcpConnection(
            self, self.log, self.loop, hostinfo=util.hostportjoin(host, port)),
                                                        host,
                                                        port,
                                                        ssl=self.
                                                        _ssl_context_factory())

        self._pool[(host, port)] = protocol

        return protocol
Exemplo n.º 5
0
    def hostinfo(self):
        host, port = self._transport.get_extra_info('peername')[:2]

        if port == COAP_PORT:
            port = None

        return util.hostportjoin(host, port)
Exemplo n.º 6
0
    def setUp(self):
        super(WithProxyServer, self).setUp()

        self.forwardproxy = aiocoap.cli.proxy.Main([
            "--forward", "--bind",
            hostportjoin(self.proxyhost, self.proxyport)
        ])
        self.loop.run_until_complete(self.forwardproxy.initializing)
Exemplo n.º 7
0
    def setUp(self):
        super(WithReverseProxy, self).setUp()

        self.reverseproxy = aiocoap.cli.proxy.Main(
                ["--reverse", "--bind", hostportjoin(self.proxyhost, self.proxyport), "--namebased", "%s:%s"%(self.name_for_real_server, self.servernetloc), "--pathbased", "%s:%s"%("/".join(self.path_for_real_server), self.servernetloc)],
                loop=self.loop,
                )
        self.loop.run_until_complete(self.reverseproxy.initializing)
Exemplo n.º 8
0
    async def _spawn_protocol(self, message):
        if message.unresolved_remote is None:
            host = message.opt.uri_host
            port = message.opt.uri_port or self._default_port
            if host is None:
                raise ValueError("No location found to send message to (neither in .opt.uri_host nor in .remote)")
        else:
            host, port = util.hostportsplit(message.unresolved_remote)
            port = port or self._default_port

        if (host, port) in self._pool:
            return self._pool[(host, port)]

        _, protocol = await self.loop.create_connection(
                lambda: TcpConnection(self, self.log, self.loop,
                    hostinfo=util.hostportjoin(host, port)),
                host, port,
                ssl=self._ssl_context_factory())

        self._pool[(host, port)] = protocol

        return protocol
Exemplo n.º 9
0
 def hostinfo(self):
     if self._hostinfo:
         return self._hostinfo
     peername = self._transport.get_extra_info('peername')
     return util.hostportjoin(peername[0], peername[1])
Exemplo n.º 10
0
    def hostinfo_local(self):
        host, port = self._transport.get_extra_info('sockname')[:2]

        return util.hostportjoin(host, port)
Exemplo n.º 11
0
    def setUp(self):
        super().setUp()

        self.rd = aiocoap.cli.rd.Main(['--bind', hostportjoin('::1', self.rd_port)])
        self.loop.run_until_complete(self.rd.initializing)
Exemplo n.º 12
0
    def setUp(self):
        super().setUp()

        self.rd = aiocoap.cli.rd.Main(
            ['--bind', hostportjoin('::1', self.rd_port)])
        self.loop.run_until_complete(self.rd.initializing)
Exemplo n.º 13
0
 def hostinfo(self):
     if self._hostinfo:
         return self._hostinfo
     peername = self._transport.get_extra_info('peername')
     return util.hostportjoin(peername[0], peername[1])
Exemplo n.º 14
0
import asyncio
import unittest
import tempfile
import shutil

import aiocoap
import aiocoap.defaults
from aiocoap.util import hostportjoin

from .test_server import WithAsyncLoop, WithClient, asynctest
from . import common
from .fixtures import test_is_successful

from .common import PYTHON_PREFIX
SERVER_ADDRESS = '::1'
SERVER = PYTHON_PREFIX + ['./contrib/oscore-plugtest/plugtest-server', '--verbose', '--bind', hostportjoin(SERVER_ADDRESS, None)]
CLIENT = PYTHON_PREFIX + ['./contrib/oscore-plugtest/plugtest-client', '--verbose']

class CapturingSubprocess(asyncio.SubprocessProtocol):
    """This protocol just captures stdout and stderr into properties of the
    same name.

    Unlike using communicate() on a create_subprocess_exec product, this does
    not discard any output that was collected when the task is cancelled, and
    thus allows cleanup.

    No way of passing data into the process is implemented, as it is not needed
    here."""

    def __init__(self):
        self.stdout = b""
Exemplo n.º 15
0
 def hostinfo_local(self):
     return util.hostportjoin(*self._local_hostinfo)
Exemplo n.º 16
0
 def hostinfo(self):
     # keeping _remote_hostinfo and _local_hostinfo around structurally rather than in
     # hostinfo / hostinfo_local form looks odd now, but on the long run the
     # remote should be able to tell the message what its default Uri-Host
     # value is
     return util.hostportjoin(*self._remote_hostinfo)
Exemplo n.º 17
0
import asyncio
import unittest
import tempfile
import shutil

import aiocoap
import aiocoap.defaults
from aiocoap.util import hostportjoin

from .test_server import WithAsyncLoop, WithClient, asynctest
from . import common
from .fixtures import test_is_successful

from .common import PYTHON_PREFIX
SERVER_ADDRESS = '::1'
SERVER = PYTHON_PREFIX + ['./contrib/oscore-plugtest/plugtest-server', '--verbose', '--bind', hostportjoin(SERVER_ADDRESS, None)]
CLIENT = PYTHON_PREFIX + ['./contrib/oscore-plugtest/plugtest-client', '--verbose']

class CapturingSubprocess(asyncio.SubprocessProtocol):
    """This protocol just captures stdout and stderr into properties of the
    same name.

    Unlike using communicate() on a create_subprocess_exec product, this does
    not discard any output that was collected when the task is cancelled, and
    thus allows cleanup.

    No way of passing data into the process is implemented, as it is not needed
    here."""

    def __init__(self):
        self.stdout = b""
Exemplo n.º 18
0
import unittest

import aiocoap
import aiocoap.defaults
from aiocoap.util import hostportjoin

from .test_server import WithAsyncLoop, WithClient, asynctest
from . import common
from .fixtures import test_is_successful

from .common import PYTHON_PREFIX

SERVER_ADDRESS = '::1'
SERVER = PYTHON_PREFIX + [
    './contrib/oscore-plugtest/plugtest-server', '--verbose', '--bind',
    hostportjoin(SERVER_ADDRESS, None)
]
CLIENT = PYTHON_PREFIX + [
    './contrib/oscore-plugtest/plugtest-client', '--verbose'
]


class CapturingSubprocess(asyncio.SubprocessProtocol):
    """This protocol just captures stdout and stderr into properties of the
    same name.

    Unlike using communicate() on a create_subprocess_exec product, this does
    not discard any output that was collected when the task is cancelled, and
    thus allows cleanup.

    No way of passing data into the process is implemented, as it is not needed
Exemplo n.º 19
0
    def setUp(self):
        super(WithReverseProxy, self).setUp()

        self.reverseproxy = aiocoap.cli.proxy.Main(["--reverse", "--bind", hostportjoin(self.proxyhost, self.proxyport), "--namebased", "%s:%s"%(self.name_for_real_server, self.servernetloc), "--pathbased", "%s:%s"%("/".join(self.path_for_real_server), self.servernetloc)])
        self.loop.run_until_complete(self.reverseproxy.initializing)