From 264167e3d1ab2e9dd703bf62fe46c50e7b4cb502 Mon Sep 17 00:00:00 2001 From: Matthieu BRIEDA Date: Wed, 14 Mar 2018 17:24:57 +0100 Subject: [PATCH 1/6] Update Blocklayer to deal with Block1 option On the last block answer, the Client still sent another empty message, it didn't take into account the fact that the previous block was sent with m=0. This commit fixed that for me. --- coapthon/layers/blocklayer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/coapthon/layers/blocklayer.py b/coapthon/layers/blocklayer.py index 451ba3c..8f698a3 100644 --- a/coapthon/layers/blocklayer.py +++ b/coapthon/layers/blocklayer.py @@ -141,10 +141,10 @@ class BlockLayer(object): item.num += 1 item.byte += item.size if len(item.payload) <= item.byte: - m = 0 + item.m = 0 else: - m = 1 - request.block1 = (item.num, m, item.size) + item.m = 1 + request.block1 = (item.num, item.m, item.size) elif transaction.response.block2 is not None: num, m, size = transaction.response.block2 From ce3f4ba843cc320ee0b562586aa164b0668f70ce Mon Sep 17 00:00:00 2001 From: Hannes Date: Wed, 9 May 2018 19:13:39 +0200 Subject: [PATCH 2/6] combined multicast and unicast sockets to one socket --- coapthon/server/coap.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/coapthon/server/coap.py b/coapthon/server/coap.py index 5a52102..4518309 100644 --- a/coapthon/server/coap.py +++ b/coapthon/server/coap.py @@ -79,16 +79,10 @@ class CoAP(object): # Join group if addrinfo[0] == socket.AF_INET: # IPv4 self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) - - # Allow multiple copies of this program on one machine - # (not strictly needed) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self._socket.bind((defines.ALL_COAP_NODES, self.server_address[1])) + self._socket.bind(('', self.server_address[1])) mreq = struct.pack("4sl", socket.inet_aton(defines.ALL_COAP_NODES), socket.INADDR_ANY) self._socket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) - self._unicast_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self._unicast_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self._unicast_socket.bind(self.server_address) else: self._socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP) @@ -104,7 +98,6 @@ class CoAP(object): self._unicast_socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) self._unicast_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._unicast_socket.bind(self.server_address) - else: if addrinfo[0] == socket.AF_INET: # IPv4 self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -252,10 +245,7 @@ class CoAP(object): logger.debug("send_datagram - " + str(message)) serializer = Serializer() message = serializer.serialize(message) - if self.multicast: - self._unicast_socket.sendto(message, (host, port)) - else: - self._socket.sendto(message, (host, port)) + self._socket.sendto(message, (host, port)) def add_resource(self, path, resource): """ From c88afef47b22abade87379b3ddda2567c8789092 Mon Sep 17 00:00:00 2001 From: "giacomo.tanganelli@for.unipi.it" Date: Fri, 11 May 2018 15:59:48 +0200 Subject: [PATCH 3/6] get_non implemented for clients --- coapthon/client/helperclient.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/coapthon/client/helperclient.py b/coapthon/client/helperclient.py index 986be8b..af2a693 100644 --- a/coapthon/client/helperclient.py +++ b/coapthon/client/helperclient.py @@ -99,6 +99,24 @@ class HelperClient(object): return self.send_request(request, callback, timeout) + def get_non(self, path, callback=None, timeout=None, **kwargs): # pragma: no cover + """ + Perform a GET on a certain path. + + :param path: the path + :param callback: the callback function to invoke upon response + :param timeout: the timeout of the request + :return: the response + """ + request = self.mk_request_non(defines.Codes.GET, path) + request.token = generate_random_token(2) + + for k, v in kwargs.items(): + if hasattr(request, k): + setattr(request, k, v) + + return self.send_request(request, callback, timeout) + def observe(self, path, callback, timeout=None, **kwargs): # pragma: no cover """ Perform a GET with observe on a certain path. @@ -233,4 +251,19 @@ class HelperClient(object): request.uri_path = path return request + def mk_request_non(self, method, path): + """ + Create a request. + + :param method: the CoAP method + :param path: the path of the request + :return: the request + """ + request = Request() + request.destination = self.server + request.code = method.number + request.uri_path = path + request.type = defines.Types["NON"] + return request + From de4d34cf498600ec99d551d8427350408e37d235 Mon Sep 17 00:00:00 2001 From: "giacomo.tanganelli@for.unipi.it" Date: Fri, 11 May 2018 16:15:13 +0200 Subject: [PATCH 4/6] server logging --- coapthon/server/coap.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/coapthon/server/coap.py b/coapthon/server/coap.py index 5a52102..150c17d 100644 --- a/coapthon/server/coap.py +++ b/coapthon/server/coap.py @@ -16,15 +16,18 @@ from coapthon.messages.request import Request from coapthon.messages.response import Response from coapthon.resources.resource import Resource from coapthon.serializer import Serializer -from coapthon.utils import Tree +from coapthon.utils import Tree, create_logging import collections __author__ = 'Giacomo Tanganelli' -logger = logging.getLogger(__name__) +if not os.path.isfile("logging.conf"): + create_logging() +logger = logging.getLogger(__name__) +logging.config.fileConfig("logging.conf", disable_existing_loggers=False) class CoAP(object): """ From 17673ebced1ae5da6d02aa3ec2915df278b2bc35 Mon Sep 17 00:00:00 2001 From: giacomo Date: Thu, 20 Sep 2018 18:12:11 +0200 Subject: [PATCH 5/6] logging --- coapthon/server/coap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/coapthon/server/coap.py b/coapthon/server/coap.py index feb5a24..b3dfd6c 100644 --- a/coapthon/server/coap.py +++ b/coapthon/server/coap.py @@ -29,6 +29,7 @@ if not os.path.isfile("logging.conf"): logger = logging.getLogger(__name__) logging.config.fileConfig("logging.conf", disable_existing_loggers=False) + class CoAP(object): """ Implementation of the CoAP server From 95fd89d7a20ddaf89e811110b07fb781fd1751c5 Mon Sep 17 00:00:00 2001 From: Hannes Hansen Date: Sun, 2 Dec 2018 13:22:40 +0100 Subject: [PATCH 6/6] fixed problem with nested endpoints --- coapthon/server/coap.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/coapthon/server/coap.py b/coapthon/server/coap.py index b3dfd6c..99d2757 100644 --- a/coapthon/server/coap.py +++ b/coapthon/server/coap.py @@ -273,8 +273,6 @@ class CoAP(object): except KeyError: res = None if res is None: - if len(paths) != i: - return False resource.path = actual_path self.root[actual_path] = resource return True