Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

gossip

gossip is a Clojure library to do gossip dissemination of messages in a decentralized manner over unreliable networks.

It is based on the paper Peer-to-Peer Membership Management for Gossip-Based Protocols

Clojars Project

Latest codox API docs

WARNING WARNING WARNING: The messages gossiped between nodes are not encrypted, they are sent as plaintext, use at your own discretion.

Usage

;;;; Note: To accurately witness the dissemination;;;; capabilities, there should be a non-trivial amount;;;; of nodes in the network. The following example;;;; sacrifices that for brevity's sake but you;;;; should be able to expand it on your own easily,;;;; the library is intended to be a low-level building;;;; block for customized abstractions after all.
(require '[gossip.core :refer [create-node send-initial
handle-message
schedule-heartbeat-send
schedule-heartbeat-dec
get-id gossip]]
'[gossip.utils :refer [receive]]
'[udp-wrapper.core :refer [create-udp-server close-udp-server
empty-packet localhost]])
;; Get this machine's ip address as a string.
(defip (.getHostAddress (localhost)))
;; Create nodes with this machine's ip address and different port numbers.
(defnode1 (ref (create-node ip 6601)))
(defnode2 (ref (create-node ip 6602)))
;; Create a socket for each node.
(defsocket1 (create-udp-server6601))
(defsocket2 (create-udp-server6602))
;; Start a receiving loop for each node, handle-message;; does pattern matching on the received messages and;; dispatches accordingly.
(deffut1 (receive socket1 (empty-packet512) node1 handle-message))
(deffut2 (receive socket2 (empty-packet512) node2 handle-message))
;; Send a heartbeat every 30 seconds to all nodes in;; each node's partial-view
(schedule-heartbeat-send socket1 node1 (*1000605))
(schedule-heartbeat-send socket2 node2 (*1000605))
;; Decrease the heartbeat-counter of each node;; every 5 minutes.
(schedule-heartbeat-dec socket1 node1 (*1000605))
(schedule-heartbeat-dec socket2 node2 (*1000605))
;; Send an InitialSubscription from node1 to node2.
(send-initial socket1 node1 (get-id @node2))
;; Gossip the message to all nodes in node1's partial-view.
(gossip socket1 node1 "No one shall expel us from the paradise that Cantor has created.")
;; Shutdown
(future-cancel fut1)
(future-cancel fut2)
(close-udp-server socket1)
(close-udp-server socket2)

TODO

  • Survey the Clojure testing facilities and decide on one.
  • Seriously! MOAR TESTS!
  • Proper validation for IDs and messages.
  • DTLS.
  • Implement indirection.
  • Implement lease functionality.
  • Decouple the design parameter?

License

MIT

About

gossip is a Clojure library to do gossip dissemination of messages in a decentralized manner over unreliable networks.

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages