rdrp

package module
v0.0.0-...-6a5b4e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 10 Imported by: 0

README

rdrp

A cross-platform command line tool for sending and receiving files over your local network, inspired by AirDrop.

Contents

Demo

Design

rdrp uses Multicast DNS to enable peer-to-peer discovery between clients. This means that rdrp will likely not work in most cloud/virtual environments.

When a client first connects, they're registered as a new instance on the _rdrp._tcp service. Each sender continuously browses this service for newly connected broadcasters with whom they'll establish a connection and attempt to send their respective file.

This program implements mDNS with grandcat/zeroconf.

Read more about mDNS: RFC 6762 and DNS-SD: RFC 6763.

Installation / setup

Go should be installed and configured.

Install with Go:

$ go get -v github.com/kashav/rdrp/...
$ which rdrp
$GOPATH/bin/rdrp

Or, install directly via source:

$ git clone https://github.com/kashav/rdrp.git $GOPATH/src/github.com/kashav/rdrp
$ cd $_ # $GOPATH/src/github.com/kashav/rdrp
$ make install all
$ ./rdrp

Usage

Run rdrp with the --help flag to view the usage dialogue.

$ rdrp --help
usage: rdrp [<flags>] <command> [<args> ...]

Send and receive files over your local network.

Flags:
      --help       Show context-sensitive help (also try --help-long and --help-man).
  -n, --name=NAME  Set your connection name.
  -d, --debug      Enable debug mode.
      --version    Show application version.

Commands:
  help [<command>...]
    Show help.

  broadcast
    Receive a file.

  list [<flags>]
    View active clients.

  send [<flags>]
    Send a file.

There's two parties involved in a single transaction: the sender and the receiver.

Send

To send a file, use the send command. Provide the file path with the --file flag or pass the file's contents via stdin.

Every broadcaster will receive a request to transfer the file (unless names are specified with the --to flag). This process continues until aborted (Ctrl+C).

$ rdrp help send
usage: rdrp send [<flags>]

Send a file.

Flags:
      --help       Show context-sensitive help (also try --help-long and --help-man).
  -n, --name=NAME  Set your connection name.
  -d, --debug      Enable debug mode.
      --version    Show application version.
  -f, --file=FILE  Specify the transfer file (you may optionally pass your file via stdin).
      --to=TO ...  Comma-separated list of client names.

Examples
$ rdrp send --file=README.md
$ rdrp send --name sender < README.md
$ tar -cvzf archive.tar.gz /path/to/directory/
$ rdrp send --file=archive.tar.gz --to=a
$ echo "hello" | rdrp send --to=b,c
Broadcast

To broadcast yourself as a receiver (i.e. someone receiving a file), use the broadcast command.

You'll be listening for incoming send requests. Upon a new connection, you'll be prompted on whether you'd like to accept the file or not, just like AirDrop. The incoming file is copied to stdout.

$ rdrp broadcast -help
usage: rdrp broadcast

Receive a file.

Flags:
      --help       Show context-sensitive help (also try --help-long and --help-man).
  -n, --name=NAME  Set your connection name.
  -d, --debug      Enable debug mode.
      --version    Show application version.

Examples
$ rdrp broadcast # output is copied to stdout
...
$ rdrp broadcast --name b > archive.tar.gz

Note that each of the above roles has an optional name flag, a name is chosen at random if not provided (which is what happened in the demo above).

List

You can view all connected clients with list. Use --type to specify the type of clients to list and --watch to listen for new connections.

$ rdrp list -help

View active clients.

Flags:
      --help        Show context-sensitive help (also try --help-long and --help-man).
  -n, --name=NAME   Set your connection name.
  -d, --debug       Enable debug mode.
      --version     Show application version.
  -w, --watch       Watch for new connections.
  -t, --type="all"  Specify which type of client to listen for.

Use with Docker

Start off by cloning the repository (if you've already cloned, navigate to the project root):

$ git clone https://github.com/kashav/rdrp
$ cd rdrp

Build the Docker image:

$ docker build -t kashav/rdrp .

And run it! The --rm flag automatically removes the container when the program exits.

$ docker run --rm kashav/rdrp [broadcast|list|send] ...

Contribute

This project is completely open source, feel free to open an issue or submit a pull request.

Before submitting a PR, please ensure that tests are passing and that the linter is happy. The following commands may be of use.

$ make install \
       get-tools
$ make fmt \
       vet \
       lint
$ make test \
       coverage

The demo GIF was generated with asciinema, with tmux.

License

rdrp source code is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateName

func GenerateName() string

GenerateName sets the seed and generates a random 2-word, hyphen-separated name.

func Start

func Start(r Runner) (err error)

Start finds an open port and calls the runner's work function.

Types

type Broadcaster

type Broadcaster struct {
	Client Client
}

Broadcaster represents a broadcast client.

func NewBroadcaster

func NewBroadcaster(client Client) *Broadcaster

NewBroadcaster returns a new Broadcaster.

func (Broadcaster) Work

func (b Broadcaster) Work() (err error)

Work creates a server and starts listening for file transfer requests.

type Client

type Client struct {
	Command string
	Name    string
}

Client represents common config. for each connected client.

type Lister

type Lister struct {
	Client Client

	Watch      bool
	ClientType string
}

Lister represents a list client.

func NewLister

func NewLister(client Client, watch bool, clientType string) *Lister

NewLister returns a new Lister.

func (*Lister) Work

func (l *Lister) Work() (err error)

Work creates a server and starts finding and listing connected clients.

type Runner

type Runner interface {
	Work() error
}

Runner represents a connected client.

type Sender

type Sender struct {
	Client Client

	FileName string
	Clients  []string
}

Sender represents a send client.

func NewSender

func NewSender(client Client, fileName string, clients []string) *Sender

NewSender returns a new Sender and zeroes the seen map.

func (*Sender) Work

func (s *Sender) Work() (err error)

Work creates a server and starts discovering Broadcasters.

Directories

Path Synopsis
cmd
rdrp command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL