Git Product home page Git Product logo

anygram's Introduction

AnyGram

Datagram forwarding behind NAT

Anygram uses STUN to get the mapped address, IRC to signal peers.

Install

npm -g install anygram@latest

CLI

Server

anygram -n [serverNick] -m server -P [serverPort]

Client

anygram -n [clientNick] -m client -s [serverNick] -p [clientPort] -P [serverPort]

The commands above will forward packets to 127.0.0.1:clientPort@client to 127.0.0.1:serverPort@server. For more options, see anygram --help

To run the commands forever, consider using forever

API

var anygram = require('anygram')(config);

config uses the same command line options.

In AnyGram, all sockets are UDP sockets.

anygram.punch(socket)

Returns a promise of socket. socket.rinfo may change if the remote NAT is symmetric. The punching process usually succeeds if not both NATs are symmetric.

socket is a UDP socket plus two attributes linfo and rinfo, obtained by calling anygram.stun

The rinfo.punchTime attribute also indicates when to start punching. This option is to make sure both sides start punching at the same time in spite of the (sometimes huge) IRC time lag.

anygram.stun(stunServer)

Returns a promise of socket. socket.linfo will include the mapped port, address and the NAT type.

stunServer is the hostname of a stun server listening at 3478

anygram.irc(config)

Returns an IRC client.

The config should specify the name and pass(if any) of your IRC account. The IRC server's host and port are optional. The client will send PING packets at the keepalive interval.

anygram.connect(irc, to, rinfo)

Returns a promise of socket.

irc is the IRC client

to is the name of the peer you are connecting to

rinfo(optional) is specified if you already got peer's rinfo

anygram.createServer(irc, onconn, onerr)

Start listening on the irc client for incoming connections

onconn is called when connected with a peer successfully

onerr is called on error

anygram.send(socket, msg, lport, rport)

Sends msg with 4 bytes header (lport and rport)

anygram.onrecv(socket, cb)

Parses received messages to cb(msg, lport, rport)

Notice that the rport@remote will become lport@local and vice versa.

Credits

anygram's People

Contributors

isofew avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.