I'm trying to recreate some functionality of NearDrop, a MacOS app to interact with Android NearbyShare functionality.
Namely, I want to create a program that's visible in NearbyShare.
The repo has a description of the NearbyShare protocol and says that to be visible to Android devices you must advertise an mDNS service with specific properties.
The domain must be empty, the type is _FC9F5ED42C8A._tcp.
, and the name is set to a specific 10-byte sequence encoded in URL safe base 64.
I tried to replicate this in python 3.10 using the python-zeroconf library, but I get a BadTypeInNameException
.
name = bytes([
0x23, # PCP
*bytes("AAAA", 'utf-8'), # endpointID
0xFC, 0x9F, 0x5E, # Service ID hash
0, 0
])
endpoint_info = bytes([
0b00000110, # version: 000, visibility: 0 (visible), device type: 011 (3 = laptop), 0
*([0x00]*16), # unknown purpose
0b00000110, # name length 6
*bytes('mycomp', 'utf-8')
])
protocol_name = "_FC9F5ED42C8A._tcp.local."
info = ServiceInfo(
protocol_name,
''.join(chr(c) for c in urlsafe_b64encode(name)),
addresses=[socket.inet_aton("127.0.0.1")],
port=80,
properties={'n': urlsafe_b64encode(endpoint_info)},
server="ash-2.local.",
)
I think according to the specification the name needs to end width the type and the type needs to end in .local.
, or at least the python package enforces something like this.
What confuses me most is that the original Swift implementation doesn't seem to have a problem with this.
Did I interpreted the description of the protocol wrongly? or do I need to somehow force different behavior from the python library?