Guest User

Untitled

a guest
May 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. const IlpStream = require('ilp-protocol-stream')
  2. const createPlugin = require('ilp-plugin')
  3.  
  4. const serverPlugin = createPlugin()
  5. const server = await IlpStream.createServer({
  6. plugin: serverPlugin
  7. })
  8.  
  9. server.on('connection', (connection) => {
  10. console.log('server got connection')
  11.  
  12. connection.on('stream', (stream) => {
  13. console.log(`server got a new stream: ${stream.id}`)
  14.  
  15. // Set the maximum amount of money this stream can receive
  16. stream.setReceiveMax(10000)
  17.  
  18. // Handle incoming money
  19. stream.on('money', (amount) => {
  20. console.log(`server stream ${stream.id} got incoming payment for: ${amount}`)
  21. })
  22.  
  23. // Handle incoming data
  24. stream.on('data', (chunk) => {
  25. console.log(`server stream ${stream.id} got data: ${chunk.toString('utf8')}`)
  26. })
  27. })
  28. })
  29.  
  30. // These would need to be passed from the server to the client using
  31. // some encrypted communication channel (not provided by STREAM)
  32. const { destinationAccount, sharedSecret } = server.generateAddressAndSecret()
  33. console.log(`server generated ILP address (${destinationAccount}) and shared secret (${sharedSecret.toString('hex')}) for client`)
Add Comment
Please, Sign In to add comment