Skip to content

An open-source cross-platform alternative to AirDrop

feat: change multicast address and make it configurable

Tien Do Nam857a7eee77fa
diff --git a/assets/i18n/_missing_translations.json b/assets/i18n/_missing_translations.json
index 0663c45d..9e9cc863 100644
--- a/assets/i18n/_missing_translations.json
+++ b/assets/i18n/_missing_translations.json
@@ -7,7 +7,9 @@
"settingsTab": {
"network": {
"portWarning": "You might not be detected by other devices because you are using a custom port. (default: {defaultPort})",
- "encryption": "Encryption"
+ "encryption": "Encryption",
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
}
},
"receiveHistoryPage": {
@@ -47,17 +49,14 @@
}
}
},
- "de": {
- "sendPage": {
- "busy": "The recipient is busy with another request."
- },
- "dialogs": {
- "errorDialog": {
- "title": "@:general.error"
- }
- }
- },
+ "de": {},
"es-ES": {
+ "settingsTab": {
+ "network": {
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
+ }
+ },
"sendPage": {
"busy": "The recipient is busy with another request."
},
@@ -68,6 +67,12 @@
}
},
"fr-FR": {
+ "settingsTab": {
+ "network": {
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
+ }
+ },
"sendPage": {
"busy": "The recipient is busy with another request."
},
@@ -78,6 +83,12 @@
}
},
"hu": {
+ "settingsTab": {
+ "network": {
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
+ }
+ },
"sendPage": {
"busy": "The recipient is busy with another request."
},
@@ -88,6 +99,12 @@
}
},
"in": {
+ "settingsTab": {
+ "network": {
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
+ }
+ },
"receiveHistoryPage": {
"title": "History",
"empty": "The history is empty.",
@@ -122,6 +139,12 @@
}
},
"it": {
+ "settingsTab": {
+ "network": {
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
+ }
+ },
"receiveHistoryPage": {
"title": "History",
"empty": "The history is empty.",
@@ -159,7 +182,9 @@
"settingsTab": {
"network": {
"portWarning": "You might not be detected by other devices because you are using a custom port. (default: {defaultPort})",
- "encryption": "Encryption"
+ "encryption": "Encryption",
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
}
},
"receiveHistoryPage": {
@@ -200,6 +225,12 @@
}
},
"ja": {
+ "settingsTab": {
+ "network": {
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
+ }
+ },
"sendPage": {
"busy": "The recipient is busy with another request."
},
@@ -210,6 +241,12 @@
}
},
"ko": {
+ "settingsTab": {
+ "network": {
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
+ }
+ },
"receiveHistoryPage": {
"title": "History",
"empty": "The history is empty.",
@@ -247,7 +284,9 @@
"settingsTab": {
"network": {
"portWarning": "You might not be detected by other devices because you are using a custom port. (default: {defaultPort})",
- "encryption": "Encryption"
+ "encryption": "Encryption",
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
}
},
"receiveHistoryPage": {
@@ -291,7 +330,9 @@
"settingsTab": {
"network": {
"portWarning": "You might not be detected by other devices because you are using a custom port. (default: {defaultPort})",
- "encryption": "Encryption"
+ "encryption": "Encryption",
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
}
},
"receiveHistoryPage": {
@@ -332,6 +373,12 @@
}
},
"pt-BR": {
+ "settingsTab": {
+ "network": {
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
+ }
+ },
"sendPage": {
"busy": "The recipient is busy with another request."
},
@@ -356,7 +403,9 @@
"settingsTab": {
"network": {
"portWarning": "You might not be detected by other devices because you are using a custom port. (default: {defaultPort})",
- "encryption": "Encryption"
+ "encryption": "Encryption",
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
}
},
"receiveHistoryPage": {
@@ -400,7 +449,9 @@
"settingsTab": {
"network": {
"portWarning": "You might not be detected by other devices because you are using a custom port. (default: {defaultPort})",
- "encryption": "Encryption"
+ "encryption": "Encryption",
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
}
},
"receiveHistoryPage": {
@@ -441,40 +492,20 @@
}
},
"tr": {
- "receiveHistoryPage": {
- "title": "History",
- "empty": "The history is empty.",
- "entryActions": {
- "open": "Open file",
- "info": "Information",
- "deleteFromHistory": "Delete from history"
- }
- },
- "sendPage": {
- "busy": "The recipient is busy with another request."
- },
- "dialogs": {
- "addressInput": {
- "recentlyUsed": "Recently used: "
- },
- "cannotOpenFile": {
- "title": "Cannot open file",
- "content": "Could not open \"{file}\". Has this file been moved, renamed or deleted?"
- },
- "errorDialog": {
- "title": "@:general.error"
- },
- "fileInfo": {
- "title": "File information",
- "fileName": "File name:",
- "path": "Path:",
- "size": "Size:",
- "sender": "Sender:",
- "time": "Time:"
+ "settingsTab": {
+ "network": {
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
}
}
},
"zh-Hans": {
+ "settingsTab": {
+ "network": {
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
+ }
+ },
"receiveHistoryPage": {
"empty": "The history is empty."
},
@@ -502,7 +533,9 @@
"settingsTab": {
"network": {
"portWarning": "You might not be detected by other devices because you are using a custom port. (default: {defaultPort})",
- "encryption": "Encryption"
+ "encryption": "Encryption",
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
}
},
"receiveHistoryPage": {
@@ -546,7 +579,9 @@
"settingsTab": {
"network": {
"portWarning": "You might not be detected by other devices because you are using a custom port. (default: {defaultPort})",
- "encryption": "Encryption"
+ "encryption": "Encryption",
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
}
},
"receiveHistoryPage": {
diff --git a/assets/i18n/strings.i18n.json b/assets/i18n/strings.i18n.json
index 79ee653d..6ab88aa3 100644
--- a/assets/i18n/strings.i18n.json
+++ b/assets/i18n/strings.i18n.json
@@ -95,7 +95,9 @@
"alias": "Alias",
"port": "Port",
"portWarning": "You might not be detected by other devices because you are using a custom port. (default: {defaultPort})",
- "encryption": "Encryption"
+ "encryption": "Encryption",
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "You might not be detected by other devices because you are using a custom multicast address. (default: {defaultMulticast})"
}
},
"receiveHistoryPage": {
diff --git a/assets/i18n/strings_de.i18n.json b/assets/i18n/strings_de.i18n.json
index f7470458..ea70a2f6 100644
--- a/assets/i18n/strings_de.i18n.json
+++ b/assets/i18n/strings_de.i18n.json
@@ -95,7 +95,9 @@
"alias": "Alias",
"port": "Port",
"portWarning": "Möglicherweise wirst du von anderen Geräten nicht erkannt, weil du einen benutzerdefinierten Port verwendest. (Standard: {defaultPort})",
- "encryption": "Verschlüsselung"
+ "encryption": "Verschlüsselung",
+ "multicastGroup": "Multicast",
+ "multicastGroupWarning": "Möglicherweise wirst du von anderen Geräten nicht erkannt, weil du eine benutzerdefinierte Multicast-Adresse verwendest. (Standard: {defaultMulticast})"
}
},
"receiveHistoryPage": {
@@ -126,7 +128,8 @@
},
"sendPage": {
"waiting": "Warte auf Antwort...",
- "rejected": "Der Empfänger hat die Anfrage abgelehnt."
+ "rejected": "Der Empfänger hat die Anfrage abgelehnt.",
+ "busy": "Der Empfänger ist mit einer anderen Anfrage beschäftigt."
},
"progressPage": {
"titleSending": "Sende Dateien",
@@ -176,6 +179,9 @@
"title": "Verschlüsselung deaktiviert",
"content": "Die Kommunikation erfolgt nun über das unverschlüsselte HTTP-Protokoll. Um HTTPS zu verwenden, aktiviere wieder die Verschlüsselung."
},
+ "errorDialog": {
+ "title": "@:general.error"
+ },
"fileInfo": {
"title": "Datei-Information",
"fileName": "Dateiname:",
diff --git a/lib/constants.dart b/lib/constants.dart
index ca2ad51e..1c87d639 100644
--- a/lib/constants.dart
+++ b/lib/constants.dart
@@ -1 +1,8 @@
+/// The default http server port and
+/// and multicast port.
const defaultPort = 53317;
+
+/// The default multicast group should be 224.0.0.0/24
+/// because on some Android devices this is the only IP range
+/// that can receive UDP multicast messages.
+const defaultMulticastGroup = '224.0.0.167';
diff --git a/lib/model/settings.dart b/lib/model/settings.dart
index a5bed657..ade5d4e9 100644
--- a/lib/model/settings.dart
+++ b/lib/model/settings.dart
@@ -12,6 +12,7 @@ class Settings with _$Settings {
required ThemeMode theme,
required AppLocale? locale,
required int port,
+ required String multicastGroup,
required String? destination, // null = default
required bool saveToGallery, // only Android, iOS
required bool quickSave, // automatically accept file requests
diff --git a/lib/pages/debug/multicast_debug_page.dart b/lib/pages/debug/multicast_debug_page.dart
index a1afb463..ce925559 100644
--- a/lib/pages/debug/multicast_debug_page.dart
+++ b/lib/pages/debug/multicast_debug_page.dart
@@ -26,6 +26,11 @@ class MulticastDebugPage extends ConsumerWidget {
onPressed: () => ref.read(nearbyDevicesProvider.notifier).startMulticastScan(),
child: const Text('Announce'),
),
+ const SizedBox(width: 20),
+ ElevatedButton(
+ onPressed: () => ref.read(multicastLogsProvider.notifier).clear(),
+ child: const Text('Clear'),
+ ),
],
),
const SizedBox(height: 20),
diff --git a/lib/pages/tabs/settings_tab.dart b/lib/pages/tabs/settings_tab.dart
index f835098b..a9a4228f 100644
--- a/lib/pages/tabs/settings_tab.dart
+++ b/lib/pages/tabs/settings_tab.dart
@@ -31,6 +31,7 @@ class SettingsTab extends ConsumerStatefulWidget {
class _SettingsTabState extends ConsumerState<SettingsTab> {
final _aliasController = TextEditingController();
final _portController = TextEditingController();
+ final _multicastController = TextEditingController();
@override
void initState() {
@@ -38,6 +39,7 @@ class _SettingsTabState extends ConsumerState<SettingsTab> {
final settings = ref.read(settingsProvider);
_aliasController.text = settings.alias;
_portController.text = settings.port.toString();
+ _multicastController.text = settings.multicastGroup;
}
@override
@@ -306,6 +308,16 @@ class _SettingsTabState extends ConsumerState<SettingsTab> {
}
},
),
+ _SettingsEntry(
+ label: t.settingsTab.network.multicastGroup,
+ child: TextFormField(
+ controller: _multicastController,
+ textAlign: TextAlign.center,
+ onChanged: (s) async {
+ await ref.read(settingsProvider.notifier).setMulticastGroup(s);
+ },
+ ),
+ ),
AnimatedCrossFade(
crossFadeState: settings.port != defaultPort ? CrossFadeState.showSecond : CrossFadeState.showFirst,
duration: const Duration(milliseconds: 200),
@@ -313,7 +325,23 @@ class _SettingsTabState extends ConsumerState<SettingsTab> {
firstChild: Container(),
secondChild: Padding(
padding: const EdgeInsets.only(bottom: 15),
- child: Text(t.settingsTab.network.portWarning(defaultPort: defaultPort), style: const TextStyle(color: Colors.grey)),
+ child: Text(
+ t.settingsTab.network.portWarning(defaultPort: defaultPort),
+ style: const TextStyle(color: Colors.grey),
+ ),
+ ),
+ ),
+ AnimatedCrossFade(
+ crossFadeState: settings.multicastGroup != defaultMulticastGroup ? CrossFadeState.showSecond : CrossFadeState.showFirst,
+ duration: const Duration(milliseconds: 200),
+ alignment: Alignment.topLeft,
+ firstChild: Container(),
+ secondChild: Padding(
+ padding: const EdgeInsets.only(bottom: 15),
+ child: Text(
+ t.settingsTab.network.multicastGroupWarning(defaultMulticast: defaultMulticastGroup),
+ style: const TextStyle(color: Colors.grey),
+ ),
),
),
],
diff --git a/lib/provider/multicast_logs_provider.dart b/lib/provider/multicast_logs_provider.dart
index d4fe6cbf..f42994a5 100644
--- a/lib/provider/multicast_logs_provider.dart
+++ b/lib/provider/multicast_logs_provider.dart
@@ -14,4 +14,8 @@ class MulticastLogsNotifier extends StateNotifier<List<LogEntry>> {
LogEntry(timestamp: DateTime.now(), log: log),
].take(200).toList();
}
+
+ void clear() {
+ state = [];
+ }
}
diff --git a/lib/provider/network/multicast_provider.dart b/lib/provider/network/multicast_provider.dart
index 574c03f1..abde0e6d 100644
--- a/lib/provider/network/multicast_provider.dart
+++ b/lib/provider/network/multicast_provider.dart
@@ -13,8 +13,6 @@ import 'package:localsend_app/provider/settings_provider.dart';
import 'package:localsend_app/util/device_info_helper.dart';
import 'package:localsend_app/util/sleep.dart';
-const _multicastGroup = '224.0.245.133';
-
final multicastProvider = Provider((ref) {
final deviceInfo = ref.watch(deviceRawInfoProvider);
return MulticastService(ref, deviceInfo);
@@ -42,7 +40,7 @@ class MulticastService {
final settings = _ref.read(settingsProvider);
final fingerprint = _ref.read(fingerprintProvider);
- final sockets = await _getSockets(_multicastGroup, settings.port);
+ final sockets = await _getSockets(settings.multicastGroup, settings.port);
for (final socket in sockets) {
socket.socket.listen((_) {
final datagram = socket.socket.receive();
@@ -67,7 +65,7 @@ class MulticastService {
_ref.read(multicastLogsProvider.notifier).addLog(e.toString());
}
});
- _ref.read(multicastLogsProvider.notifier).addLog('Bind UDP multicast port (ip: ${socket.interface.addresses.map((a) => a.address).toList()}, group: $_multicastGroup, port: ${settings.port})');
+ _ref.read(multicastLogsProvider.notifier).addLog('Bind UDP multicast port (ip: ${socket.interface.addresses.map((a) => a.address).toList()}, group: ${settings.multicastGroup}, port: ${settings.port})');
}
// Tell everyone in the network that I am online
@@ -79,7 +77,7 @@ class MulticastService {
/// Sends an announcement which triggers a response on every LocalSend member of the network.
Future<void> sendAnnouncement() async {
final settings = _ref.read(settingsProvider);
- final sockets = await _getSockets(_multicastGroup);
+ final sockets = await _getSockets(settings.multicastGroup);
final dto = _getDto(announcement: true);
for (final wait in [100, 500, 1000, 2000]) {
await sleepAsync(wait);
@@ -87,7 +85,7 @@ class MulticastService {
_ref.read(multicastLogsProvider.notifier).addLog('Sending announcement');
for (final socket in sockets) {
try {
- socket.socket.send(dto, InternetAddress(_multicastGroup), settings.port);
+ socket.socket.send(dto, InternetAddress(settings.multicastGroup), settings.port);
socket.socket.close();
} catch (e) {
_ref.read(multicastLogsProvider.notifier).addLog(e.toString());
@@ -100,11 +98,11 @@ class MulticastService {
Future<void> _answerAnnouncement() async {
_ref.read(multicastLogsProvider.notifier).addLog('Answering announcement');
final settings = _ref.read(settingsProvider);
- final sockets = await _getSockets(_multicastGroup);
+ final sockets = await _getSockets(settings.multicastGroup);
final dto = _getDto(announcement: false);
for (final socket in sockets) {
try {
- socket.socket.send(dto, InternetAddress(_multicastGroup), settings.port);
+ socket.socket.send(dto, InternetAddress(settings.multicastGroup), settings.port);
socket.socket.close();
} catch (e) {
_ref.read(multicastLogsProvider.notifier).addLog(e.toString());
diff --git a/lib/provider/persistence_provider.dart b/lib/provider/persistence_provider.dart
index cf95ff78..81cd0249 100644
--- a/lib/provider/persistence_provider.dart
+++ b/lib/provider/persistence_provider.dart
@@ -26,6 +26,7 @@ const _aliasKey = 'ls_alias';
const _themeKey = 'ls_theme';
const _localeKey = 'ls_locale';
const _portKey = 'ls_port';
+const _multicastGroupKey = 'ls_multicast_group';
const _destinationKey = 'ls_destination';
const _saveToGallery = 'ls_save_to_gallery';
const _quickSave = 'ls_quick_save';
@@ -119,6 +120,14 @@ class PersistenceService {
await _prefs.setInt(_portKey, port);
}
+ String getMulticastGroup() {
+ return _prefs.getString(_multicastGroupKey) ?? defaultMulticastGroup;
+ }
+
+ Future<void> setMulticastGroup(String group) async {
+ await _prefs.setString(_multicastGroupKey, group);
+ }
+
String? getDestination() {
return _prefs.getString(_destinationKey);
}
diff --git a/lib/provider/settings_provider.dart b/lib/provider/settings_provider.dart
index 00f45fe1..1e8fe5e9 100644
--- a/lib/provider/settings_provider.dart
+++ b/lib/provider/settings_provider.dart
@@ -21,6 +21,7 @@ class SettingsNotifier extends StateNotifier<Settings> {
theme: service.getTheme(),
locale: service.getLocale(),
port: service.getPort(),
+ multicastGroup: service.getMulticastGroup(),
destination: service.getDestination(),
saveToGallery: service.isSaveToGallery(),
quickSave: service.isQuickSave(),
@@ -58,6 +59,13 @@ class SettingsNotifier extends StateNotifier<Settings> {
);
}
+ Future<void> setMulticastGroup(String group) async {
+ await _service.setMulticastGroup(group);
+ state = state.copyWith(
+ multicastGroup: group,
+ );
+ }
+
Future<void> setDestination(String? destination) async {
await _service.setDestination(destination);
state = state.copyWith(