Skip to content

Commit

Permalink
Merge branch 'master' of github.com:telehash/node-telehash
Browse files Browse the repository at this point in the history
  • Loading branch information
quartzjer committed Jun 4, 2014
2 parents 74b1729 + 5c85551 commit ccefd3f
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Overview

[![telehash](https://nodei.co/npm/telehash.png)](https://nodei.co/npm/telehash/)

This module presents a simple high-level API for using [telehash](https://github.com/telehash/telehash.org/blob/master/protocol.md) for both node and browserify.

The browser crypto that powers this is only possible thanks to the incredible work done by the team behind [Forge](https://github.com/digitalbazaar/forge), [Tom Wu](http://www-cs-students.stanford.edu/~tjw/), and the [Sanford Javascript Crypto Library](https://github.com/bitwiseshiftleft/sjcl).
Expand Down Expand Up @@ -46,3 +46,56 @@ The first object passed in to the `load` function takes the following arguments:
## API

Once you have a hashname running you can use the [common API](https://github.com/telehash/thjs#API) with it.

Below is a trivial example, taking off from a properly initialized switch. For an "In the wild" example, see [ndn-telehashTransport](https://github.com/rynomad/ndn-telehashTransport), which allows one to use telehash for named data networking.

```js
channelName = "AWESOME"

funcion packetHandler(err, packet, chan, callback){
//check for error
if (err) return console.log("oh noes, we got an error! ", err);

//packet.js and packet.body are your json message and binary data(if present)
console.log(packet.js, packet.body) // {myName: "Steve"}, null <-- see firstPacket below

//call the callback with true to send an ack and recieve subsequent packets
callback(true)

//send a response
var response = {
js: {
isAwesome: true,
ownsCat: false,
interests: [
"telehash",
"dogs",
"bad horror movies"
]
}
body: myPreconstrucedBuffer //some Uint8Array.buffer or node.js Buffer.buffer
}
chan.send(response)

}
//begin listening for incoming packets on a channel named 'AWESOME'
self.listen(channelName, packetHandler)

//start a channel to another hashname, assuming they have the listener above
//(hashname given generated by use of keyboard smashing, you should use a real hashname)

firstPacket = {
js: {
myName: "Steve"
}
}

targetHashname = "fj04f4mc5405085mq043q04c48u5mc045mc09mwq098m4c03m084c50493"

self.start(targetHashname, channelName, firstPacket, packetHandler)






0 comments on commit ccefd3f

Please sign in to comment.