Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
cda0d64
Add a mDNS package
sgjesse Oct 28, 2015
5242a77
Fix warning and hint int test
sgjesse Oct 28, 2015
8394100
Correct two typos.
karlklose Oct 29, 2015
3147614
Extend the mDNS package with a native extension used on Mac OS
sgjesse Nov 2, 2015
1aecdd0
Revert "Extend the mDNS package with a native extension used on Mac OS"
sgjesse Nov 2, 2015
b753a49
Re-land "Extend the mDNS package with a native extension used on Mac OS"
sgjesse Nov 3, 2015
bd21b36
Improve resource record implementation in the mdns package.
karlklose Nov 6, 2015
5eae734
Minor fixes to the mDNS package
sgjesse Nov 10, 2015
be10902
Update the mDNS command line tools in the mdns package
sgjesse Nov 10, 2015
67e73fc
Update the mDNS native extension for Mac OS to handle PTR and SRV rec…
sgjesse Nov 10, 2015
51c2879
Add multiple results and timeout handling to the Mac OS mDNS native e…
sgjesse Nov 10, 2015
8ba84d1
Add mDNS discovery to the Fletch compiler
sgjesse Nov 10, 2015
2b2fe61
Avoid a warning due to bug in Dart SDK
sgjesse Nov 10, 2015
afd0ffa
Update project authors statements to Dartino
mit-mit Jan 28, 2016
27e32bb
Rename fletch -> dartino
ricowind Feb 3, 2016
a02b198
Update Dart binaries to 1.18.0-dev.4.4
karlklose Jul 28, 2016
372e481
Move the serial_port native code
sgjesse Aug 3, 2016
13440cc
Initial refactor/adding of mdns
dnfield Oct 18, 2018
a062a28
Initial refactor/adding of mdns
dnfield Oct 18, 2018
0a158b2
move helper methods to tool/
dnfield Oct 18, 2018
cf98f1f
update docs, add example
dnfield Oct 18, 2018
2d8f0ab
merge
dnfield Oct 18, 2018
f962358
remove RRType.any - not ready
dnfield Oct 18, 2018
a223011
README
dnfield Oct 18, 2018
1ae7747
remove lint ignore, update CI
dnfield Oct 18, 2018
8a711b9
update CI for non-flutter packages
dnfield Oct 18, 2018
60f3635
update regex
dnfield Oct 18, 2018
a935aee
revert incremental_build.sh
dnfield Oct 18, 2018
4aba212
Update docs, expose multicast parameter
dnfield Oct 19, 2018
cefc13b
fix tests, run analyze first
dnfield Oct 19, 2018
dcf69e4
Fix readme for mDNS
dnfield Oct 19, 2018
2c09d26
move bin to example, remove args from main pubspec
dnfield Oct 20, 2018
d0071bd
Update example
dnfield Oct 20, 2018
af7a0df
Remove collection dep
dnfield Oct 20, 2018
14826cb
Fix unintentional change to Palette, avoid abbreviations, real hash c…
dnfield Oct 22, 2018
f3a79a8
vertical alignment
dnfield Oct 22, 2018
b9572ba
dartfmt and remove all references to args package
dnfield Oct 23, 2018
9dbb4dd
cleanup
dnfield Oct 24, 2018
5bcabe2
typo, word wrap
dnfield Oct 24, 2018
1961d9f
Add type parameters
dnfield Oct 24, 2018
0eb9bc1
Update examples to use type parameters
dnfield Oct 25, 2018
d379223
minor fixes
dnfield Nov 2, 2018
8d3c4e2
Merge remote-tracking branch 'upstream/master'
dnfield Nov 7, 2018
64902f4
remvoe debugging cde
dnfield Nov 7, 2018
b8251d9
move dumpDatagram to tools
dnfield Nov 7, 2018
2ad7aea
format
dnfield Nov 7, 2018
09b47d2
Set socket options
dnfield Jan 17, 2019
0962e7d
bump
dnfield Jan 19, 2019
3d2f2a4
update version constraint, fix analyzer issues
dnfield Jan 19, 2019
4a0974d
Merge remote-tracking branch 'upstream/master'
dnfield Jan 23, 2019
de88b93
Fix cache, var names, comments
dnfield Jan 24, 2019
3602baa
one missed comment
dnfield Jan 24, 2019
bceebbd
missed renames
dnfield Jan 24, 2019
b5b1d4e
formatting
dnfield Jan 24, 2019
554ac6f
missing comment
dnfield Jan 24, 2019
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
Prev Previous commit
Next Next commit
Fix unintentional change to Palette, avoid abbreviations, real hash c…
…ode impl
  • Loading branch information
dnfield committed Oct 22, 2018
commit 14826cb2bb59d6019a9e39076d4d4d67c2923b8b
4 changes: 2 additions & 2 deletions packages/multicast_dns/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ void main() async {
await client.start();

// Get the PTR recod for the service.
await for (PtrResourceRecord ptr in client.lookup(RRType.ptr, name)) {
await for (PtrResourceRecord ptr in client.lookup(ResourceRecordType.ptr, name)) {
// Use the domainName from the PTR record to get the SRV record,
// which will have the port and local hostname.
// Note that duplicate messages may come through, especially if any
// other mDNS queries are running elsewhere on the machine.
await for (SrvResourceRecord srv
in client.lookup(RRType.srv, ptr.domainName)) {
in client.lookup(ResourceRecordType.srv, ptr.domainName)) {
// Domain name will be something like "[email protected]._dartobservatory._tcp.local"
final String bundleId =
ptr.domainName.substring(0, ptr.domainName.indexOf('@'));
Expand Down
4 changes: 2 additions & 2 deletions packages/multicast_dns/example/mdns-resolve.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ For example:
await client.start();
final Duration timeout = Duration(seconds: int.parse(arguments['timeout']));
await for (IPAddressResourceRecord record
in client.lookup(RRType.a, name, timeout: timeout)) {
in client.lookup(ResourceRecordType.a, name, timeout: timeout)) {
print('Found address (${record.address}).');
}

await for (IPAddressResourceRecord record
in client.lookup(RRType.aaaa, name, timeout: timeout)) {
in client.lookup(ResourceRecordType.aaaa, name, timeout: timeout)) {
print('Found address (${record.address}).');
}
client.stop();
Expand Down
10 changes: 5 additions & 5 deletions packages/multicast_dns/example/mdns-sd.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@ For example:
final MDnsClient client = MDnsClient();
await client.start();

await for (PtrResourceRecord ptr in client.lookup(RRType.ptr, name)) {
await for (PtrResourceRecord ptr in client.lookup(ResourceRecordType.ptr, name)) {
if (verbose) {
print(ptr);
}
await for (SrvResourceRecord srv
in client.lookup(RRType.srv, ptr.domainName)) {
in client.lookup(ResourceRecordType.srv, ptr.domainName)) {
if (verbose) {
print(srv);
}
if (verbose) {
await client.lookup(RRType.txt, ptr.domainName).forEach(print);
await client.lookup(ResourceRecordType.txt, ptr.domainName).forEach(print);
}
await for (IPAddressResourceRecord ip
in client.lookup(RRType.a, srv.target)) {
in client.lookup(ResourceRecordType.a, srv.target)) {
if (verbose) {
print(ip);
}
print(
'Service instance found at ${srv.target}:${srv.port} with ${ip.address}.');
}
await for (IPAddressResourceRecord ip
in client.lookup(RRType.aaaa, srv.target)) {
in client.lookup(ResourceRecordType.aaaa, srv.target)) {
if (verbose) {
print(ip);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/multicast_dns/lib/mdns_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MDnsClient {

/// Lookup a [ResourceRecord], potentially from cache.
///
/// The [type] parameter must be a valid [RRType]. The [name] parameter is
/// The [type] parameter must be a valid [ResourceRecordType]. The [name] parameter is
/// the name of the service to lookup, and must not be null. The [timeout]
/// parameter specifies how long the intenral cache should hold on to the
/// record. The [multicast] parameter specifies whether the query should be
Expand All @@ -142,7 +142,7 @@ class MDnsClient {
Duration timeout = const Duration(seconds: 5),
bool multicast = true,
}) {
RRType.debugAssertValid(type);
ResourceRecordType.debugAssertValid(type);
assert(multicast != null);
assert(name != null);

Expand Down
10 changes: 9 additions & 1 deletion packages/multicast_dns/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ InternetAddress mDnsAddressIPv6 = InternetAddress('FF02::FB');
const int mDnsPort = 5353;

/// Enumeration of supported resource record class types.
class RRClass {
class ResourceRecordClass {
// This class is intended to be used as a namespace, and should not be
// extended directly.
factory ResourceRecordClass._() => null;

/// Internet address class ("IN").
static const int internet = 1;
}

/// Enumeration of DNS question types.
class QuestionType {
// This class is intended to be used as a namespace, and should not be
// extended directly.
factory QuestionType._() => null;

/// "QU" Question.
static const int unicast = 0x8000;

Expand Down
2 changes: 1 addition & 1 deletion packages/multicast_dns/lib/src/lookup_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PendingRequest extends LinkedListEntry<PendingRequest> {
/// Creates a new PendingRequest.
PendingRequest(this.type, this.name, this.controller);

/// The [RRType] of the request.
/// The [ResourceRecordType] of the request.
final int type;

/// The domain name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a little more detail? Is this the domain name of the host that the request is going to? Is it just the domain, or is it a full hostname? (e.g. flutter.io vs docs.flutter.io)

Expand Down
2 changes: 1 addition & 1 deletion packages/multicast_dns/lib/src/native_protocol_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ResourceRecordCache {

/// Get a record from this cache.
void lookup(String name, int type, List<ResourceRecord> results) {
RRType.debugAssertValid(type);
ResourceRecordType.debugAssertValid(type);
final int time = DateTime.now().millisecondsSinceEpoch;
for (int i = _position + size; i >= _position; i--) {
final int index = i % size;
Expand Down
57 changes: 29 additions & 28 deletions packages/multicast_dns/lib/src/packet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ List<String> processDnsNameParts(String name) {

/// Encode an mDNS query packet.
///
/// The [type] parameter must be a valid [RRType] value. The [multicast] parameter
/// The [type] parameter must be a valid [ResourceRecordType] value. The [multicast] parameter
/// must not be null.
List<int> encodeMDnsQuery(
String name, {
int type = RRType.a,
int type = ResourceRecordType.a,
bool multicast = true,
}) {
assert(name != null);
RRType.debugAssertValid(type);
ResourceRecordType.debugAssertValid(type);
assert(multicast != null);

final List<String> nameParts = processDnsNameParts(name);
Expand Down Expand Up @@ -86,7 +86,7 @@ List<int> encodeMDnsQuery(
offset += 2;
bd.setUint16(
offset,
RRClass.internet |
ResourceRecordClass.internet |
(multicast ? QuestionType.multicast : QuestionType.unicast));

return data;
Expand Down Expand Up @@ -179,15 +179,15 @@ List<ResourceRecord> decodeMDnsResponse(List<int> packet) {

final Uint8List data =
packet is Uint8List ? packet : Uint8List.fromList(packet);
final ByteData bd = ByteData.view(data.buffer);
final ByteData packetBytes = ByteData.view(data.buffer);
// Number of answers.
final int ancount = bd.getUint16(_kAncountOffset);
final int ancount = packetBytes.getUint16(_kAncountOffset);
if (ancount == 0) {
return null;
}

// Number of resource records.
final int arcount = bd.getUint16(_kArcountOffset);
final int arcount = packetBytes.getUint16(_kArcountOffset);
int offset = _kHeaderSize;

void checkLength(int required) {
Expand All @@ -198,72 +198,72 @@ List<ResourceRecord> decodeMDnsResponse(List<int> packet) {

ResourceRecord readResourceRecord() {
// First read the FQDN.
final _FQDNReadResult result = _readFQDN(data, bd, offset, length);
final _FQDNReadResult result = _readFQDN(data, packetBytes, offset, length);
final String fqdn = result.fqdn;
offset += result.bytesRead;
checkLength(offset + 2);
final int type = bd.getUint16(offset);
final int type = packetBytes.getUint16(offset);
offset += 2;
// The first bit of the rrclass field is set to indicate that the answer is
// unique and the querier should flush the cached answer for this name
// (RFC 6762, Sec. 10.2). We ignore it for now since we don't cache answers.
checkLength(offset + 2);
final int cls = bd.getUint16(offset) & 0x7fff;
final int resourceRecordClass = packetBytes.getUint16(offset) & 0x7fff;

if (cls != RRClass.internet) {
if (resourceRecordClass != ResourceRecordClass.internet) {
// We do not support other classes.
return null;
}

offset += 2;
checkLength(offset + 4);
final int ttl = bd.getInt32(offset);
final int ttl = packetBytes.getInt32(offset);
offset += 4;

checkLength(offset + 2);
final int rDataLength = bd.getUint16(offset);
final int rDataLength = packetBytes.getUint16(offset);
offset += 2;
final int validUntil = DateTime.now().millisecondsSinceEpoch + ttl * 1000;
switch (type) {
case RRType.a:
case ResourceRecordType.a:
checkLength(offset + rDataLength);
final StringBuffer addr = StringBuffer();
final int stop = offset + rDataLength;
addr.write(bd.getUint8(offset));
addr.write(packetBytes.getUint8(offset));
offset++;
for (offset; offset < stop; offset++) {
addr.write('.');
addr.write(bd.getUint8(offset));
addr.write(packetBytes.getUint8(offset));
}
return IPAddressResourceRecord(fqdn, validUntil,
address: InternetAddress(addr.toString()));
case RRType.aaaa:
case ResourceRecordType.aaaa:
checkLength(offset + rDataLength);

final StringBuffer addr = StringBuffer();
final int stop = offset + rDataLength;
addr.write(bd.getUint16(offset).toRadixString(16));
addr.write(packetBytes.getUint16(offset).toRadixString(16));
offset += 2;
for (offset; offset < stop; offset += 2) {
addr.write(':');
addr.write(bd.getUint16(offset).toRadixString(16));
addr.write(packetBytes.getUint16(offset).toRadixString(16));
}
return IPAddressResourceRecord(
fqdn,
validUntil,
address: InternetAddress(addr.toString()),
);
case RRType.srv:
case ResourceRecordType.srv:
checkLength(offset + 2);
final int priority = bd.getUint16(offset);
final int priority = packetBytes.getUint16(offset);
offset += 2;
checkLength(offset + 2);
final int weight = bd.getUint16(offset);
final int weight = packetBytes.getUint16(offset);
offset += 2;
checkLength(offset + 2);
final int port = bd.getUint16(offset);
final int port = packetBytes.getUint16(offset);
offset += 2;
final _FQDNReadResult result = _readFQDN(data, bd, offset, length);
final _FQDNReadResult result =
_readFQDN(data, packetBytes, offset, length);
offset += result.bytesRead;
return SrvResourceRecord(
fqdn,
Expand All @@ -274,16 +274,17 @@ List<ResourceRecord> decodeMDnsResponse(List<int> packet) {
weight: weight,
);
break;
case RRType.ptr:
case ResourceRecordType.ptr:
checkLength(offset + rDataLength);
final _FQDNReadResult result = _readFQDN(data, bd, offset, length);
final _FQDNReadResult result =
_readFQDN(data, packetBytes, offset, length);
offset += rDataLength;
return PtrResourceRecord(
fqdn,
validUntil,
domainName: result.fqdn,
);
case RRType.txt:
case ResourceRecordType.txt:
checkLength(offset + rDataLength);
final Uint8List rawText = Uint8List.view(
data.buffer,
Expand Down
Loading