Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.
/ airlib Public archive

Peer to peer file transfer library for Dart

License

Notifications You must be signed in to change notification settings

synw/airlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Airlib

Peer to peer file transfer library for Dart. Powered by Node commander

Initialization

Run a soldier node where to read the files from:

import 'package:nodecommander/nodecommander.dart';
import 'package:airlib/airlib.dart';

final ip = await getHost();
final soldier = AirlinkSoldier.fromIp(ip, name: "node1", verbose: true);
await soldier.init();

Run a commander node that will be able to download files:

final commander = AirlinkCommander.fromIp(ip,
   name: "airlib commander", port: 8088, verbose: true);
await commander.init();

Auto discover soldier nodes

await commander.node.discoverNodes();
await Future<dynamic>.delayed(const Duration(seconds: 1));
if (commander.node.soldiers.isNotEmpty) {
   final soldier = commander.node.soldiers[0];
}

Send commands

ls: directory listing

final cmd = commander.cmd("ls").copyWithArguments(<dynamic>["."]);
await commander.sendCommand(cmd, soldier.address);
/// to do something with the result listen to the 
/// command results stream
commander.listen((cmd) {
  switch (cmd.name) {
    case "ls":
      final listing = DirectoryListing.fromJson(cmd.payload);
      print(listing.format("-l"));
      break;
    default:
  }
});

Note: the NodeCommand model is immutable. Commands have to be copied instead of mutated

wget: download a file

await commander.sendCommand(
  commander
      .cmd("wget")
      .copyWithArguments(<dynamic>["/some/path/file.txt"]),
  s.address);

Use the cli

Run a soldier node then start the cli: dart bin/main.dart

Screenshot

Soldier node:

Screenshot

Example

To run the example:

  • dart bin main.dart to start the soldier node
  • dart bin main.dart -c to start the commander node

About

Peer to peer file transfer library for Dart

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages