0.2.1 • Published 7 years ago

cjdns-admin v0.2.1

Weekly downloads
14
License
-
Repository
github
Last release
7 years ago

cjdns-admin


A nodejs module for working with the CJDNS admin interface over UDP. It's made to be consistent, robust and easy to use.

Jump:

Install


It's available via npm

npm install cjdns-admin

createAdmin constructor


The createAdmin function returns an EventEmitter4 with members for each admin function and their alternate. It also contains members which handle automatic paging for functions which are paged.

Options:

  • ip, string, optional
  • port, number, optional
  • password, string, required

Usage:

var cjdnsAdmin = require('cjdns-admin'),
    admin,
    channel;

// create a new Admin
admin = cjdnsAdmin.createAdmin({
    ip: '127.0.0.1',
    port: 11234,
    password: 'my cjdns password'
});

// ping the admin
channel = admin.ping();

// create a response handler
function pingResponse (res) {
    // process ping response
    console.dir(res);
}

// handle the response
admin.on(channel, pingResponse);

CJDNS Admin functions

  • Original: named the same as CJDNS calls them
  • Alternate: consistent with normal JS function nomenclature
  • Underneath they call the same function
OriginalAlternate
Admin_asyncEnabledadmin.asyncEnabled
Admin_availableFunctionsadmin.availableFunctions
admin.availableFunctionsPaged
AdminLog_logManylog.logMany
AdminLog_subscribelog.subscribe
AdminLog_subscriptionslog.subscriptions
AdminLog_unsubscribelog.unsubscribe
Allocator_bytesAllocatedallocator.bytesAllocated
Allocator_snapshotallocator.snapshot
AuthorizedPasswords_addauthorizedPasswords.add
AuthorizedPasswords_listauthorizedPasswords.list
AuthorizedPasswords_removeauthorizedPasswords.remove
Core_exitcore.exit
Core_initTunnelcore.initTunnel
Core_pidcore.pid
InterfaceController_disconnectPeerinterfaceController.disconnectPeer
InterfaceController_peerStatsinterfaceController.peerStats
interfaceController.peerStatsPaged
IpTunnel_allowConnectionipTunnel.allowConnection
IpTunnel_connectToipTunnel.connectTo
IpTunnel_listConnectionsipTunnel.listConnections
IpTunnel_removeConnectionipTunnel.removeConnection
IpTunnel_showConnectionipTunnel.showConnection
Janitor_dumpRumorMilljanitor.dumpRumorMill
memoryadmin.memory
nodeStore.dumpTablePaged
NodeStore_getLinknodeStore.getLink
NodeStore_getRouteLabelnodeStore.getRouteLabel
NodeStore_nodeForAddrnodeStore.nodeForAddr
pingadmin.ping
RouterModule_findNoderouterModule.findNode
RouterModule_getPeersrouterModule.getPeers
RouterModule_lookuprouterModule.lookup
RouterModule_nextHoprouterModule.nextHop
RouterModule_pingNoderouterModule.pingNode
SearchRunner_showActiveSearchsearchRunner.showActiveSearch
SearchRunner_searchsearchRunner.search
Security_checkPermissionssecurity.checkPermissions
Security_chrootsecurity.chroot
Security_getUsersecurity.getUser
Security_nofilessecurity.nofiles
Security_noforkssecurity.noforks
Security_seccompsecurity.seccomp
Security_setupCompletesecurity.setupComplete
Security_setUsersecurity.setUser
SessionManager_getHandlessessionManager.getHandles
sessionManager.getHandlesPaged
SessionManager_sessionStatssessionManager.sessionStats
SwitchPinger_pingswitchPinger.ping
UDPInterface_beginConnectionudpInterface.beginConnection
UDPInterface_newudpInterface.new

Admin_asyncEnabled, admin.asyncEnabled

Usage:

channel = admin.asyncEnabled();
admin.once(channel, processResponse);

Admin_availableFunctions, admin.availableFunctions

  • page, int, optional

Usage:

var channel,
    options;

options = {
    page: 0
};

channel = admin.availableFunctions(options);
admin.once(channel, processResponse);

AdminLog_logMany, log.logMany

  • count, int, required

Usage:

var channel,
    options;

options = {
    count: 0
};

channel = admin.log.logMany(options);
admin.once(channel, processResponse);

AdminLog_subscribe, log.subscribe

  • file, string, optional
  • level, string, optional
  • line, int, optional

Usage:

var channel,
    options;

options = {
    file: '',
    level: '',
    line: 0
};

channel = admin.log.subscribe(options);
admin.once(channel, processResponse);

AdminLog_subscriptions, log.subscriptions

Usage:

channel = admin.log.subscriptions();
admin.once(channel, processResponse);

AdminLog_unsubscribe, log.unsubscribe

  • streamId, string, required

Usage:

var channel,
    options;

options = {
    streamId: ''
};

channel = admin.log.unsubscribe(options);
admin.once(channel, processResponse);

Allocator_bytesAllocated, allocator.bytesAllocated

Usage:

channel = admin.allocator.bytesAllocated();
admin.once(channel, processResponse);

Allocator_snapshot, allocator.snapshot

  • includeAllocations, int, optional

Usage:

var channel,
    options;

options = {
    includeAllocations: 0
};

channel = admin.allocator.snapshot(options);
admin.once(channel, processResponse);

AuthorizedPasswords_add, authorizedPasswords.add

  • authType, int, optional
  • ipv6, string, optional
  • password, string, required
  • user, string, required

Usage:

var channel,
    options;

options = {
    authType: 0,
    ipv6: '',
    password: '',
    user: ''
};

channel = admin.authorizedPasswords.add(options);
admin.once(channel, processResponse);

AuthorizedPasswords_list, authorizedPasswords.list

Usage:

channel = admin.authorizedPasswords.list();
admin.once(channel, processResponse);

AuthorizedPasswords_remove, authorizedPasswords.remove

  • user, string, required

Usage:

var channel,
    options;

options = {
    user: ''
};

channel = admin.authorizedPasswords.remove(options);
admin.once(channel, processResponse);

Core_exit, core.exit

Usage:

channel = admin.core.exit();
admin.once(channel, processResponse);

Core_initTunnel, core.initTunnel

  • desiredTunName, string, optional

Usage:

var channel,
    options;

options = {
    desiredTunName: ''
};

channel = admin.core.initTunnel(options);
admin.once(channel, processResponse);

Core_pid, core.pid

Usage:

channel = admin.core.pid();
admin.once(channel, processResponse);

InterfaceController_disconnectPeer, interfaceController.disconnectPeer

  • pubkey, string, required

Usage:

var channel,
    options;

options = {
    pubkey: ''
};

channel = admin.interfaceController.disconnectPeer(options);
admin.once(channel, processResponse);

InterfaceController_peerStats, interfaceController.peerStats

  • page, int, optional

Usage:

var channel,
    options;

options = {
    page: 0
};

channel = admin.interfaceController.peerStats(options);
admin.once(channel, processResponse);

IpTunnel_allowConnection, ipTunnel.allowConnection

  • ip4Address, string, optional
  • ip4Prefix, int, optional
  • ip6Address, string, optional
  • ip6Prefix, int, optional
  • publicKeyOfAuthorizedNode, string, required

Usage:

var channel,
    options;

options = {
    ip4Address: '',
    ip4Prefix: 0,
    ip6Address: '',
    ip6Prefix: 0,
    publicKeyOfAuthorizedNode: ''
};

channel = admin.ipTunnel.allowConnection(options);
admin.once(channel, processResponse);

IpTunnel_connectTo, ipTunnel.connectTo

  • publicKeyOfNodeToConnectTo, string, required

Usage:

var channel,
    options;

options = {
    publicKeyOfNodeToConnectTo: ''
};

channel = admin.ipTunnel.connectTo(options);
admin.once(channel, processResponse);

IpTunnel_listConnections, ipTunnel.listConnections

Usage:

channel = admin.ipTunnel.listConnections();
admin.once(channel, processResponse);

IpTunnel_removeConnection, ipTunnel.removeConnection

  • connection, int, required

Usage:

var channel,
    options;

options = {
    connection: 0
};

channel = admin.ipTunnel.removeConnection(options);
admin.once(channel, processResponse);

IpTunnel_showConnection, ipTunnel.showConnection

  • connection, int, required

Usage:

var channel,
    options;

options = {
    connection: 0
};

channel = admin.ipTunnel.showConnection(options);
admin.once(channel, processResponse);

Janitor_dumpRumorMill, janitor.dumpRumorMill

  • mill, string, required
  • page, int, required

Usage:

var channel,
    options;

options = {
    mill: '',
    page: 0
};

channel = admin.janitor.dumpRumorMill(options);
admin.once(channel, processResponse);

memory, admin.memory

Usage:

channel = admin.memory();
admin.once(channel, processResponse);

NodeStore_dumpTable, nodeStore.dumpTable

  • page, int, required

Usage:

var channel,
    options;

options = {
    page: 0
};

channel = admin.nodeStore.dumpTable(options);
admin.once(channel, processResponse);

NodeStore_getLink, nodeStore.getLink

  • linkNum, int, required
  • parent, string, optional

Usage:

var channel,
    options;

options = {
    linkNum: 0,
    parent: ''
};

channel = admin.nodeStore.getLink(options);
admin.once(channel, processResponse);

NodeStore_getRouteLabel, nodeStore.getRouteLabel

  • pathParentToChild, string, required
  • pathToParent, string, required

Usage:

var channel,
    options;

options = {
    pathParentToChild: '',
    pathToParent: ''
};

channel = admin.nodeStore.getRouteLabel(options);
admin.once(channel, processResponse);

NodeStore_nodeForAddr, nodeStore.nodeForAddr

  • ip, string, optional

Usage:

var channel,
    options;

options = {
    ip: ''
};

channel = admin.nodeStore.nodeForAddr(options);
admin.once(channel, processResponse);

ping, admin.ping

Usage:

channel = admin.ping();
admin.once(channel, processResponse);

RouterModule_findNode, routerModule.findNode

  • nodeToQuery, string, required
  • target, string, required
  • timeout, int, optional

Usage:

var channel,
    options;

options = {
    nodeToQuery: '',
    target: '',
    timeout: 0
};

channel = admin.routerModule.findNode(options);
admin.once(channel, processResponse);

RouterModule_getPeers, routerModule.getPeers

  • nearbyPath, string, optional
  • path, string, required
  • timeout, int, optional

Usage:

var channel,
    options;

options = {
    nearbyPath: '',
    path: '',
    timeout: 0
};

channel = admin.routerModule.getPeers(options);
admin.once(channel, processResponse);

RouterModule_lookup, routerModule.lookup

  • address, string, required

Usage:

var channel,
    options;

options = {
    address: ''
};

channel = admin.routerModule.lookup(options);
admin.once(channel, processResponse);

RouterModule_nextHop, routerModule.nextHop

  • nodeToQuery, string, required
  • target, string, required
  • timeout, int, optional

Usage:

var channel,
    options;

options = {
    nodeToQuery: '',
    target: '',
    timeout: 0
};

channel = admin.routerModule.nextHop(options);
admin.once(channel, processResponse);

RouterModule_pingNode, routerModule.pingNode

  • path, string, required
  • timeout, int, optional

Usage:

var channel,
    options;

options = {
    path: '',
    timeout: 0
};

channel = admin.routerModule.pingNode(options);
admin.once(channel, processResponse);

SearchRunner_search, searchRunner.search

  • ipv6, string, required
  • maxRequests, int, optional

Usage:

var channel,
    options;

options = {
    ipv6: '',
    maxRequests: 0
};

channel = admin.searchRunner.search(options);
admin.once(channel, processResponse);

SearchRunner_showActiveSearch, searchRunner.showActiveSearch

  • number, int, required

Usage:

var channel,
    options;

options = {
    number: 0
};

channel = admin.searchRunner.showActiveSearch(options);
admin.once(channel, processResponse);

Security_checkPermissions, security.checkPermissions

Usage:

channel = admin.security.checkPermissions();
admin.once(channel, processResponse);

Security_chroot, security.chroot

  • root, string, required

Usage:

var channel,
    options;

options = {
    root: ''
};

channel = admin.security.chroot(options);
admin.once(channel, processResponse);

Security_getUser, security.getUser

  • user, string, optional

Usage:

var channel,
    options;

options = {
    user: ''
};

channel = admin.security.getUser(options);
admin.once(channel, processResponse);

Security_nofiles, security.nofiles

Usage:

channel = admin.security.nofiles();
admin.once(channel, processResponse);

Security_noforks, security.noforks

Usage:

channel = admin.security.noforks();
admin.once(channel, processResponse);

Security_seccomp, security.seccomp

Usage:

channel = admin.security.seccomp();
admin.once(channel, processResponse);

Security_setupComplete, security.setupComplete

Usage:

channel = admin.security.setupComplete();
admin.once(channel, processResponse);

Security_setUser, security.setUser

  • keepNetAdmin, int, required
  • uid, int, required

Usage:

var channel,
    options;

options = {
    keepNetAdmin: 0,
    uid: 0
};

channel = admin.security.setUser(options);
admin.once(channel, processResponse);

SessionManager_getHandles, sessionManager.getHandles

  • page, int, optional

Usage:

var channel,
    options;

options = {
    page: 0
};

channel = admin.sessionManager.getHandles(options);
admin.once(channel, processResponse);

SessionManager_sessionStats, sessionManager.sessionStats

  • handle, int, required

Usage:

var channel,
    options;

options = {
    handle: 0
};

channel = admin.sessionManager.sessionStats(options);
admin.once(channel, processResponse);

SwitchPinger_ping, switchPinger.ping

  • data, string, optional
  • keyPing, int, optional
  • path, string, required
  • timeout, int, optional

Usage:

var channel,
    options;

options = {
    data: '',
    keyPing: 0,
    path: '',
    timeout: 0
};

channel = admin.switchPinger.ping(options);
admin.once(channel, processResponse);

UDPInterface_beginConnection, udpInterface.beginConnection

  • address, string, required
  • interfaceNumber, int, optional
  • password, string, optional
  • publicKey, string, required

Usage:

var channel,
    options;

options = {
    address: '',
    interfaceNumber: 0,
    password: '',
    publicKey: ''
};

channel = admin.udpInterface.beginConnection(options);
admin.once(channel, processResponse);

UDPInterface_new, udpInterface.new

  • bindAddress, string, optional

Usage:

var channel,
    options;

options = {
    bindAddress: ''
};

channel = admin.udpInterface.new(options);
admin.once(channel, processResponse);

Paged Functions

The paged functions will fetch all pages and return the result. Passing options is optional. The callback receives err and results as arguments and both are Array types.

function pagedCallback(err, results) {
    if (err) {
        return console.log('paged callback error', err);
    }
    console.log('paged function results array', );
}
admin.availableFunctionsPaged(pagedCallback);
admin.interfaceController.peerStatsPaged(pagedCallback);
admin.nodeStore.dumpTablePaged(pagedCallback);
admin.sessionManager.getHandlesPaged(pagedCallback);

// mill property is optional
admin.janitor.dumpRumorMillPaged({ mill: '' }, pagedCallback);

Development

Create environment variables that the tests will look for:

# cjdns development environment
export CJDNS_ADMIN_PORT=11234
export CJDNS_ADMIN_IP=127.0.0.1
export CJDNS_ADMIN_PASSWORD=from your cjdroute config

Tools are available via npm scripts. See package.json in the scripts section.

npm run lint

# test offline functionality
npm test
npm test -- --watch

# test online, UDP, and potentially dangerous functions
# on an actual node
npm run test-live
npm run test-live -- --watch

# render docs to html for testing
npm run doc-gen
npm run doc-watch