Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use RelatesTo tag to recognize incoming messages #75

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions wsdiscovery/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,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 @@ -54,13 +54,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
Loading