diff --git a/sctp.py b/sctp.py index de14829..6c94eb8 100644 --- a/sctp.py +++ b/sctp.py @@ -230,7 +230,6 @@ def __init__(self, values=None): self.stream = 0 self.ssn = 0 self.flags = 0 - self.ppid = 0 self.context = 0 self.timetolive = 0 self.tsn = 0 @@ -1006,6 +1005,10 @@ class sctpsocket(object): associations, in seconds. A value of 0 means that no automatic close will be done. This property does not work for TCP-style sockets. + ttl: Default timetolive value to use with sctp_send. Default set to 0. + + streamid: Default SCTP stream identifier value to use with sctp_send. Default set to 0. + IMPORTANT NOTE: the maximum message size is limited both by the implementation and by the transmission buffer (SO_SNDBUF). SCTP applications must configure the transmission and receiving bufers accordingly to the biggest messages it @@ -1030,6 +1033,8 @@ def __init__(self, family, style, sk): self._style = style self._sk = sk self._family = family + self._ttl = 0 + self._streamid = 0 self.unexpected_event_raises_exception = False self.initparams = initparams(self) @@ -1107,7 +1112,7 @@ def getladdrs(self, assoc_id = 0): # -> tuple of sockaddrs as strings return _sctp.getladdrs(self._sk.fileno(), assoc_id) - def sctp_send(self, msg, to=("",0), ppid=0, flags=0, stream=0, timetolive=0, context=0, + def sctp_send(self, msg, to=("",0), ppid=0, flags=0, stream=None, timetolive=None, context=0, record_file_prefix="RECORD_sctp_traffic", datalogging = False): """ Sends a SCTP message. While send()/sendto() can also be used, this method also @@ -1121,7 +1126,7 @@ def sctp_send(self, msg, to=("",0), ppid=0, flags=0, stream=0, timetolive=0, con WARNING: identifying destination by Association ID not implemented yet! ppid: adaptation layer value, a 32-bit metadata that is sent along the message. - Defaults to 0. + Default to 0. flags: a bitmap of MSG_* flags. For example, MSG_UNORDERED indicates that message can be delivered out-of-order, and MSG_EOF + empty message @@ -1130,12 +1135,13 @@ def sctp_send(self, msg, to=("",0), ppid=0, flags=0, stream=0, timetolive=0, con It does NOT include flags like MSG_DONTROUTE or other low-level flags that are supported by sendto(). - stream: stream number where the message will sent by. Defaults to 0. + stream: stream number where the message will sent by. + If not set use default value. timetolive: time to live of the message in milisseconds. Zero means infinite TTL. If TTL expires, the message is discarded. Discarding policy changes whether implementation implements the PR-SCTP extension or not. - Defaults to 0 (infinite). + If not set use default value. context: an opaque 32-bit integer that will be returned in some notification events, if the event is directly related to this message transmission. So the @@ -1150,6 +1156,13 @@ def sctp_send(self, msg, to=("",0), ppid=0, flags=0, stream=0, timetolive=0, con both by the implementation and by the transmission buffer (SO_SNDBUF). The application must configure this buffer accordingly. """ + + if timetolive is None: + timetolive = self._ttl + + if stream is None: + stream = self._streamid + if datalogging == True or self.datalogging == True: now = datetime.datetime.now() recordfilename = record_file_prefix + "-" + now.strftime("%Y%m%d%H%M%S") + "-c2s." @@ -1625,6 +1638,36 @@ def set_rtoinfo(self, o): """ _sctp.set_rtoinfo(self._sk.fileno(), o.__dict__) + def get_ttl(self): + """ + Read default time to live value, 0 mean infinite + """ + return self._ttl + + def set_ttl(self, newVal): + """ + Write default time to live + """ + if not isinstance(newVal, int) or newVal < 0 or newVal > 255: + raise ValueError('TTL shall be >= 0 and <= 255') + + self._ttl = newVal + + def get_streamid(self): + """ + Read default stream identifier + """ + return self._streamid + + def set_streamid(self, newVal): + """ + Write default stream identifier + """ + if not isinstance(newVal, int) or newVal < 0 or newVal > 65535: + raise ValueError('streamid shall be a valid unsigned 16bits integer') + + self._streamid = newVal + # delegation def sock(self): @@ -1649,6 +1692,8 @@ def __getattr__(self, name): mappedv4 = property(get_mappedv4, set_mappedv4) maxseg = property(get_maxseg, set_maxseg) autoclose = property(get_autoclose, set_autoclose) + ttl = property(get_ttl, set_ttl) + streamid = property(get_streamid, set_streamid) class sctpsocket_tcp(sctpsocket): """