Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into adding_mdns_ios_support
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Mar 28, 2024
2 parents e9abd9f + 992d1da commit 2666807
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 87 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

## 2.0.1
1. Bug fixes and improvements

## 2.0.0
1. Unified framework for network_tools and network_tools_flutter

**Breaking change** Replace these occurences in your project

* HostScannerFlutter to HostScannerService.instance
* PortScannerFlutter to PortScannerService.instance


## 1.0.5

1. scanPortsForSingleDevice and customDiscover supports async mode now.
Expand Down
107 changes: 46 additions & 61 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.8.1"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints:
dependency: transitive
description:
Expand All @@ -199,26 +223,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.11.0"
multicast_dns:
dependency: transitive
description:
Expand All @@ -238,73 +262,26 @@ packages:
network_tools:
dependency: transitive
description:
path: "../../network_tools"
relative: true
source: path
version: "4.0.4"
name: network_tools
sha256: c7543a957006047d4b6e7442c2cc0f592a1dd6572a6c1024301bc11dc53d45de
url: "https://pub.dev"
source: hosted
version: "5.0.0"
network_tools_flutter:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.0.5"
nsd:
dependency: transitive
description:
name: nsd
sha256: "88a3ba4e6dc38363f1256b4b482abdeec396d99df31a064d545e559cb4cb6ba9"
url: "https://pub.dev"
source: hosted
version: "2.3.1"
nsd_android:
dependency: transitive
description:
name: nsd_android
sha256: "7a38d0b2d21f1e578cd3020940b95b22d5260413dc0c8cf30a987a4e410b166d"
url: "https://pub.dev"
source: hosted
version: "1.2.2"
nsd_ios:
dependency: transitive
description:
name: nsd_ios
sha256: "7034134dd89595362d5e464030081b0d542120a558ab7fe6227df44365df3e8a"
url: "https://pub.dev"
source: hosted
version: "1.0.3"
nsd_macos:
dependency: transitive
description:
name: nsd_macos
sha256: "2403b8d599f50fc9179db1420a0ffc25bfa8bbeb814aa31ca0a71f804fc938da"
url: "https://pub.dev"
source: hosted
version: "1.0.3"
nsd_platform_interface:
dependency: transitive
description:
name: nsd_platform_interface
sha256: "2f4033fa13cc45375253bf348abdb9712004e656462205543ec9506b43c67bb2"
url: "https://pub.dev"
source: hosted
version: "1.6.0"
nsd_windows:
dependency: transitive
description:
name: nsd_windows
sha256: "06601efdd3268cbce4b90f8e23ae1dab445c97c661fba417821ce118add722e7"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.0.0"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
path_provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -494,6 +471,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web:
dependency: transitive
description:
Expand Down
26 changes: 15 additions & 11 deletions lib/src/configure_flutter.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:logging/logging.dart';
import 'package:network_tools/network_tools.dart' as pacakges_page;
// ignore: implementation_imports
import 'package:network_tools/src/network_tools_utils.dart';
import 'package:network_tools/network_tools.dart' as packages_page;
// ignore: implementation_imports
import 'package:network_tools/src/services/arp_service.dart';
// ignore: implementation_imports
import 'package:network_tools/src/services/impls/arp_service_sembast_impl.dart';
// ignore: implementation_imports
import 'package:network_tools/src/services/impls/mdns_scanner_service_impl.dart';
import 'package:network_tools_flutter/src/network_tools_flutter_util.dart';
import 'package:network_tools_flutter/src/services_impls/host_scanner_service_flutter_impl.dart';
import 'package:network_tools_flutter/src/services_impls/mdns_scanner_service_flutter_impl.dart';
import 'package:network_tools_flutter/src/services_impls/port_scanner_service_flutter_impl.dart';
Expand All @@ -14,13 +15,13 @@ Future configureNetworkToolsFlutter(
String dbDirectory, {
bool enableDebugging = false,
}) async {
pacakges_page.enableDebugging = enableDebugging;
pacakges_page.dbDirectory = dbDirectory;
packages_page.enableDebugging = enableDebugging;
packages_page.dbDirectory = dbDirectory;

if (pacakges_page.enableDebugging) {
if (packages_page.enableDebugging) {
Logger.root.level = Level.FINE;
Logger.root.onRecord.listen((record) {
if (record.loggerName == log.name) {
if (record.loggerName == logger.name) {
// ignore: avoid_print
print(
'${record.time.toLocal()}: ${record.level.name}: ${record.loggerName}: ${record.message}',
Expand All @@ -29,12 +30,15 @@ Future configureNetworkToolsFlutter(
});
}

/// Setting dart native classes implementations
// Setting dart native classes implementations
ARPServiceSembastImpl();
MdnsScannerServiceImpl();

// Setting flutter classes implementation
HostScannerServiceFlutterImpl();
PortScannerServiceFlutterImpel();
MdnsScannerServiceFlutterImpl();
PortScannerServiceFlutterImpl();

final arpService = await ARPService.instance.open();
await arpService.buildTable();
await pacakges_page.VendorTable.createVendorTableMap();
await packages_page.VendorTable.createVendorTableMap();
}
3 changes: 3 additions & 0 deletions lib/src/network_tools_flutter_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:logging/logging.dart';

final logger = Logger("network_tools_flutter");
13 changes: 11 additions & 2 deletions lib/src/services_impls/host_scanner_service_flutter_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ class HostScannerServiceFlutterImpl extends HostScannerServiceImpl {
/// Set maxHost to higher value if you are not getting results.
/// It won't firstHostId again unless previous scan is completed due to heavy
/// resource consumption.
/// [resultsInAddressAscendingOrder] = false will return results faster but not in
/// [resultsInAddressAscendingOrder] = false will return results faster but not in order
@override
Stream<ActiveHost> getAllPingableDevices(
String subnet, {
int firstHostId = HostScannerService.defaultFirstHostId,
int lastHostId = HostScannerService.defaultLastHostId,
int timeoutInSeconds = 1,
List<int> hostIds = const [],
ProgressCallback? progressCallback,
bool resultsInAddressAscendingOrder = true,
}) async* {
Expand Down Expand Up @@ -57,7 +58,8 @@ class HostScannerServiceFlutterImpl extends HostScannerServiceImpl {
timeoutInSeconds.toString(),
resultsInAddressAscendingOrder.toString(),
dbDirectory,
enableDebugging.toString()
enableDebugging.toString(),
hostIds.join(','),
]);
} else if (message is List<String>) {
progressCallback
Expand Down Expand Up @@ -93,6 +95,12 @@ class HostScannerServiceFlutterImpl extends HostScannerServiceImpl {
final bool resultsInAddressAscendingOrder = message[4] == "true";
final String dbDirectory = message[5];
final bool enableDebugging = message[6] == "true";
final String joinedIds = message[7];
final List<int> hostIds = joinedIds
.split(',')
.where((e) => e.isNotEmpty)
.map(int.parse)
.toList();
await configureNetworkTools(dbDirectory,
enableDebugging: enableDebugging);

Expand All @@ -103,6 +111,7 @@ class HostScannerServiceFlutterImpl extends HostScannerServiceImpl {
subnetIsolate,
firstHostId: firstSubnetIsolate,
lastHostId: lastSubnetIsolate,
hostIds: hostIds,
timeoutInSeconds: timeoutInSeconds,
resultsInAddressAscendingOrder: resultsInAddressAscendingOrder,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:network_tools/network_tools.dart';
import 'package:network_tools/src/services/impls/port_scanner_service_impl.dart';

/// Flutter flavor of PortScannerService.instance, only use if your project is based of flutter.
class PortScannerServiceFlutterImpel extends PortScannerServiceImpl {
class PortScannerServiceFlutterImpl extends PortScannerServiceImpl {
/// Checks if the single [port] is open or not for the [target].
@override
Future<ActiveHost?> isOpen(
Expand Down
11 changes: 3 additions & 8 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: network_tools_flutter
description: Extended features of network_tools package for flutter framework supporting iOS and Android
version: 1.0.5
version: 2.0.1
issue_tracker: https://github.com/osociety/network_tools_flutter/issues
repository: https://github.com/osociety/network_tools_flutter

Expand Down Expand Up @@ -37,13 +37,8 @@ dependencies:
# Debugging and error logging.
logging: ^1.2.0
# Deal with internationalized/localized messages and more.
intl: ^0.18.1
# network_tools: ^4.0.3
network_tools:
path: "../network_tools"
# git:
# url: "https://github.com/guyluz11/network_tools.git"
# ref: "adding_ios_support"
intl: ^0.18.0
network_tools: ^5.0.0
path_provider: ^2.1.1
universal_io: ^2.2.2
nsd: ^2.3.1
Expand Down
47 changes: 43 additions & 4 deletions test/host_scan_flutter_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:network_tools_flutter/network_tools_flutter.dart';
import 'package:network_tools_flutter/src/network_tools_flutter_util.dart';
import 'fake_http_overrides.dart';
import 'package:universal_io/io.dart';

Expand All @@ -8,6 +9,7 @@ void main() {
int port = 0;
int firstHostId = 0;
int lastHostId = 0;
int hostId = 0;
String myOwnHost = "0.0.0.0";
String interfaceIp = myOwnHost.substring(0, myOwnHost.lastIndexOf('.'));
late ServerSocket server;
Expand All @@ -22,15 +24,15 @@ void main() {
port = server.port;
final interface = await NetInterface.localInterface();
if (interface != null) {
final hostId = interface.hostId;
hostId = interface.hostId;
interfaceIp = interface.networkId;
myOwnHost = interface.ipAddress;
// Better to restrict to scan from hostId - 1 to hostId + 1 to prevent GHA timeouts
firstHostId = hostId <= 1 ? hostId : hostId - 1;
lastHostId = hostId >= 254 ? hostId : hostId + 1;
// log.fine(
// 'Fetched own host as $myOwnHost and interface address as $interfaceIp',
// );
logger.fine(
'Fetched own host as $myOwnHost and interface address as $interfaceIp',
);
}
});

Expand All @@ -57,6 +59,43 @@ void main() {
emitsThrough(ActiveHost(internetAddress: InternetAddress(myOwnHost))),
);
});

test('Running getAllPingableDevices emits tests', () async* {
expectLater(
//There should be at least one device pingable in network
HostScannerService.instance.getAllPingableDevices(
interfaceIp,
firstHostId: firstHostId,
lastHostId: lastHostId,
),
emits(isA<ActiveHost>()),
);
});

test('Running getAllPingableDevices limiting hostId tests', () async* {
expectLater(
//There should be at least one device pingable in network when limiting to own hostId
HostScannerService.instance.getAllPingableDevices(
interfaceIp,
timeoutInSeconds: 3,
hostIds: [hostId],
firstHostId: firstHostId,
lastHostId: lastHostId,
),
emits(isA<ActiveHost>()),
);
expectLater(
//There should be at least one device pingable in network when limiting to hostId other than own
HostScannerService.instance.getAllPingableDevices(
interfaceIp,
timeoutInSeconds: 3,
hostIds: [0],
firstHostId: firstHostId,
lastHostId: lastHostId,
),
neverEmits(isA<ActiveHost>()),
);
});
});

tearDownAll(() {
Expand Down

0 comments on commit 2666807

Please sign in to comment.