forward-addr

0.1.2 • Public • Published

forward-addr

A multiaddr-inspired address format for recursivly matching protocols and properties

API

  • .parse(String str)<Object>

Returns a parsed forward-addr

Example:

console.log(fwAddr.parse('/tcp/.port/5323/ssl/.hostname/*.example.com/http/.path/"/myservice"/_ws/stream/'))
 
/*
Returns:
  [
    {protocol: 'tcp', conditions: {port: {compare: '', value: '5323'}}, action: 'stream'},
    {protocol: 'ssl', conditions: {hostname: {compare: '', value: '*.example.com'}}, action: 'stream'},
    {protocol: 'http', conditions: {path: {compare: '', value: '/myservice'}}, action: 'sub', sub: {
      protocol: 'ws', conditions: {}, action: 'stream'
    }},
  ]
*/
  • .validate(Object parsedAddr, Protocols[] protocols)<Object>

Validates the multiaddr. Throws if it is using invalid combinations of protocols, etc.

Returns a new complete parsed object where missing match fields are filled in and values are properly parsed.

Note that this mutates the parsedAddr Object

  • .match(Object parsedAddr, Object connState)<Number>

Matches a parsed address with a connection state

Returns:

  • 0: Address does not match connection state
  • 1: Address might match connection state, depending on the result of the next protocol detection
  • 2: Address matches connection state

Package Sidebar

Install

npm i forward-addr

Weekly Downloads

1

Version

0.1.2

License

MPL-2.0

Unpacked Size

16.9 kB

Total Files

14

Last publish

Collaborators

  • mkg20001