Skip to content

Add mDNS client #7

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

Merged
merged 55 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ task:
- git fetch origin master
activate_script: pub global activate flutter_plugin_tools
matrix:
- name: analyze
script: ./script/incremental_build.sh analyze
- name: publishable
script: ./script/check_publish.sh
depends_on:
- analyze
- name: test+format
install_script:
- wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
Expand All @@ -20,8 +24,8 @@ task:
- sudo apt-get install -y --allow-unauthenticated clang-format-5.0
format_script: ./script/incremental_build.sh format --travis --clang-format=clang-format-5.0
test_script: ./script/incremental_build.sh test
- name: analyze
script: ./script/incremental_build.sh analyze
depends_on:
- analyze
- name: build-apks+java-test
env:
matrix:
Expand All @@ -30,6 +34,8 @@ task:
script:
- ./script/incremental_build.sh build-examples --apk
- ./script/incremental_build.sh java-test # must come after apk build
depends_on:
- analyze

task:
use_compute_credits: $CIRRUS_USER_COLLABORATOR == 'true'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.idea
.packages
.pub/
.dart_tool/

pubspec.lock

Podfile.lock
Expand Down
5 changes: 5 additions & 0 deletions packages/multicast_dns/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 0.1.0

* Initial Open Source release.
* Migrates the dartino-sdk's mDNS client to Dart 2.0 and Flutter's analysis rules
* Breaks from original Dartino code, as it does not use native libraries for macOS and overhauls the `ResourceRecord` class.
27 changes: 27 additions & 0 deletions packages/multicast_dns/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2019 The Flutter Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 changes: 21 additions & 0 deletions packages/multicast_dns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Multicast DNS package

[![pub package](https://img.shields.io/pub/v/multicast_dns.svg)](
https://pub.dartlang.org/packages/multicast_dns)

A Dart package to do service discovery over multicast DNS (mDNS), Bonjour, and Avahi.

## Usage
To use this package, add `multicast_dns` as a
[dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).

## Example

Import the library via
``` dart
import 'package:multicast_dns/mdns_client.dart';
```

Then use the `MDnsClient` Dart class in your code. To see how this is done,
check out the [example app](example/main.dart) or the sample implementations in
the [bin](bin/) directory.
37 changes: 37 additions & 0 deletions packages/multicast_dns/example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2018, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Example script to illustrate how to use the mdns package to discover the port
// of a Dart observatory over mDNS.

import 'package:multicast_dns/multicast_dns.dart';

void main() async {
// Parse the command line arguments.

const String name = '_dartobservatory._tcp.local';
final MDnsClient client = MDnsClient();
// Start the client with default options.
await client.start();

// Get the PTR recod for the service.
await for (PtrResourceRecord ptr in client
.lookup<PtrResourceRecord>(ResourceRecordQuery.serverPointer(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<SrvResourceRecord>(
ResourceRecordQuery.service(ptr.domainName))) {
// Domain name will be something like "[email protected]._dartobservatory._tcp.local"
final String bundleId =
ptr.domainName; //.substring(0, ptr.domainName.indexOf('@'));
print('Dart observatory instance found at '
'${srv.target}:${srv.port} for "$bundleId".');
}
}
client.stop();

print('Done.');
}
34 changes: 34 additions & 0 deletions packages/multicast_dns/example/mdns-resolve.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Example script to illustrate how to use the mdns package to lookup names
// on the local network.

import 'package:multicast_dns/multicast_dns.dart';

void main(List<String> args) async {
if (args.length != 1) {
print('''
Please provide an address as argument.

For example:
dart mdns-resolve.dart dartino.local''');
return;
}

final String name = args[0];

final MDnsClient client = MDnsClient();
await client.start();
await for (IPAddressResourceRecord record in client
.lookup<IPAddressResourceRecord>(ResourceRecordQuery.addressIPv4(name))) {
print('Found address (${record.address}).');
}

await for (IPAddressResourceRecord record in client
.lookup<IPAddressResourceRecord>(ResourceRecordQuery.addressIPv6(name))) {
print('Found address (${record.address}).');
}
client.stop();
}
61 changes: 61 additions & 0 deletions packages/multicast_dns/example/mdns-sd.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Example script to illustrate how to use the mdns package to discover services
// on the local network.

import 'package:multicast_dns/multicast_dns.dart';

void main(List<String> args) async {
if (args.isEmpty) {
print('''
Please provide the name of a service as argument.

For example:
dart mdns-sd.dart [--verbose] _workstation._tcp.local''');
return;
}

final bool verbose = args.contains('--verbose') || args.contains('-v');
final String name = args.last;
final MDnsClient client = MDnsClient();
await client.start();

await for (PtrResourceRecord ptr in client
.lookup<PtrResourceRecord>(ResourceRecordQuery.serverPointer(name))) {
if (verbose) {
print(ptr);
}
await for (SrvResourceRecord srv in client.lookup<SrvResourceRecord>(
ResourceRecordQuery.service(ptr.domainName))) {
if (verbose) {
print(srv);
}
if (verbose) {
await client
.lookup<TxtResourceRecord>(ResourceRecordQuery.text(ptr.domainName))
.forEach(print);
}
await for (IPAddressResourceRecord ip
in client.lookup<IPAddressResourceRecord>(
ResourceRecordQuery.addressIPv4(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<IPAddressResourceRecord>(
ResourceRecordQuery.addressIPv6(srv.target))) {
if (verbose) {
print(ip);
}
print('Service instance found at '
'${srv.target}:${srv.port} with ${ip.address}.');
}
}
}
client.stop();
}
Loading