Skip to content

Commit

Permalink
Merge pull request andreikop#75 from wpyoga/use-relatesto
Browse files Browse the repository at this point in the history
Add option to use RelatesTo tag to recognize incoming messages
  • Loading branch information
andreikop authored Dec 13, 2024
2 parents cbb02f7 + c0bb177 commit 9290e6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 6 additions & 4 deletions wsdiscovery/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

@contextmanager
def discovery(capture=None, unicast_num=UNICAST_UDP_REPEAT,
multicast_num=MULTICAST_UDP_REPEAT):
multicast_num=MULTICAST_UDP_REPEAT, relates_to=False):
wsd = WSDiscovery(capture=capture, unicast_num=unicast_num,
multicast_num=multicast_num)
multicast_num=multicast_num, relates_to=relates_to)
wsd.start()
yield wsd
wsd.stop()
Expand Down Expand Up @@ -57,13 +57,15 @@ def setup_logger(name, loglevel):
show_default=True, help='Number of Unicast messages to send')
@click.option('--multicast-num', '-mn', type=int, default=MULTICAST_UDP_REPEAT,
show_default=True, help='Number of Multicast messages to send')
@click.option('--relates-to', '-rt', is_flag=True,
help='Also use RelatesTo tag to recognize incoming messages.')
def discover(scope, address, port, loglevel, capture, timeout, unicast_num,
multicast_num):
multicast_num, relates_to):
"Discover services using WS-Discovery"

logger = setup_logger("ws-discovery", loglevel)

with discovery(capture, unicast_num, multicast_num) as wsd:
with discovery(capture, unicast_num, multicast_num, relates_to) as wsd:
scopes = [Scope(scope)] if scope else []
svcs = wsd.searchServices(scopes=scopes, address=address, port=port,
timeout=timeout)
Expand Down
10 changes: 8 additions & 2 deletions wsdiscovery/threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(self, observer):
self._iidMap = {}
self._observer = observer
self._capture = observer._capture
self._relates_to = observer._relates_to

self._seqnum = 1 # capture sequence number
self._selector = selectors.DefaultSelector()
Expand Down Expand Up @@ -219,7 +220,10 @@ def _recvMessages(self):

mid = env.getMessageId()
if mid in self._knownMessageIds:
continue # https://github.com/andreikop/python-ws-discovery/issues/38 # TODO
if self._relates_to and env.getRelatesTo() in self._knownMessageIds:
pass
else:
continue
else:
if self._capture:
self._capture.write("NEW KNOWN MSG IDS %s\n" % (mid))
Expand Down Expand Up @@ -367,14 +371,16 @@ class ThreadedNetworking:

def __init__(self,
unicast_num=UNICAST_UDP_REPEAT,
multicast_num=MULTICAST_UDP_REPEAT, **kwargs):
multicast_num=MULTICAST_UDP_REPEAT,
relates_to=False, **kwargs):
self._networkingThread_v4 = None
self._networkingThread_v6 = None
self._addrsMonitorThread_v4 = None
self._addrsMonitorThread_v6 = None
self._serverStarted = False
self._unicast_num = unicast_num
self._multicast_num = multicast_num
self._relates_to = relates_to
super().__init__(**kwargs)

def _startThreads(self):
Expand Down

0 comments on commit 9290e6a

Please sign in to comment.