Esempio n. 1
0
    def allocate(self):
        response = self._send_request(self._build_allocate_request())
        self._nonce = response.get_attribute(STUN_ATTR_NONCE)[0]

        if (response.failed() and
            response.error()[0] == STUN_ERROR_UNAUTHORIZED):
            self._realm = response.get_attribute(STUN_ATTR_REALM)[0]
            response = self._send_request(self._build_allocate_request())

        if response.succeeded():
            _, self._relayed_port, self._relayed_address = xaddr_to_addr(
                    *response.get_attribute(STUN_ATTR_XOR_RELAYED_ADDRESS))

            self._allocation_lifetime = response.get_attribute(
                    STUN_ATTR_LIFETIME)[0]

        return response
Esempio n. 2
0
 def binding(self):
     response = self._send_request(self._build_binding_request())
     if response.succeeded():
         _, self._mapped_port, self._mapped_address= xaddr_to_addr(
                 *response.get_attribute(STUN_ATTR_XOR_MAPPED_ADDRESS))
     return response