Skip to content

Commit e212d79

Browse files
committed
Expand docstrings
1 parent 7b3688f commit e212d79

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

communityid/algo.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,37 @@ def get_data(self):
175175
return FlowTuple.Data(self.proto, saddr, daddr, sport, dport)
176176

177177
def is_ordered(self):
178-
return (self.is_one_way or self.saddr < self.daddr or
179-
(self.saddr == self.daddr and
180-
self.sport is not None and self.dport is not None and
181-
self.sport < self.dport))
178+
"""
179+
Predicate, returns True when this flow tuple is ordered.
180+
181+
A flow tuple is ordered when any of the following are true:
182+
183+
- It's marked as a one-way flow.
184+
185+
- Its source IP address is smaller than its dest IP address, both in
186+
network byte order (NBO).
187+
188+
- The IP addresses are equal and the source port is smaller than the
189+
dest port, in NBO.
190+
"""
191+
nbo = self.in_nbo()
192+
return (nbo.is_one_way or nbo.saddr < nbo.daddr or
193+
(nbo.saddr == nbo.daddr and
194+
nbo.sport is not None and nbo.dport is not None and
195+
nbo.sport < nbo.dport))
182196

183197
def has_ports(self):
198+
"""
199+
Predicate, returns True when this tuple features port numbers.
200+
"""
184201
return self.sport is not None and self.dport is not None
185202

186203
def in_order(self):
187204
"""
188-
Returns a copy of this tuple that is ordered canonically. Ie,
189-
regardless of the direction of src/dest, the returned tuple
190-
will be sorted the same way.
205+
Returns a copy of this tuple that is ordered canonically. Ie, regardless
206+
of the src/dest IP addresses and ports, the returned tuple will be be
207+
the same: the source side will contain the smaller endpoint (see
208+
FlowTuple.is_ordered() for details).
191209
"""
192210
if self.is_ordered():
193211
return FlowTuple(self.proto, self.saddr, self.daddr,

0 commit comments

Comments
 (0)