https://github.com/cipherself/gossip
gossip is a Clojure library to do gossip dissemination of messages in a decentralized manner over unreliable networks.
https://github.com/cipherself/gossip
clojure gossip gossip-dissemination
Last synced: 2 months ago
JSON representation
gossip is a Clojure library to do gossip dissemination of messages in a decentralized manner over unreliable networks.
- Host: GitHub
- URL: https://github.com/cipherself/gossip
- Owner: cipherself
- License: mit
- Created: 2015-11-22T14:28:07.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2025-11-14T10:58:08.000Z (5 months ago)
- Last Synced: 2025-12-13T04:47:25.567Z (5 months ago)
- Topics: clojure, gossip, gossip-dissemination
- Language: Clojure
- Homepage:
- Size: 48.8 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://web.archive.org/web/20240816035237/https://people.maths.bris.ac.uk/~maajg/ieeetocs03-scamp.pdf)
[](https://clojars.org/gossip)
[Latest codox API docs](https://cipherself.github.io/gossip/)
**WARNING WARNING WARNING: The messages gossiped between nodes
are not encrypted, they are sent as plaintext, use at your own
discretion.**
## Usage
```clojure
;;;; 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.
(def ip (.getHostAddress (localhost)))
;; Create nodes with this machine's ip address and different port numbers.
(def node1 (ref (create-node ip 6601)))
(def node2 (ref (create-node ip 6602)))
;; Create a socket for each node.
(def socket1 (create-udp-server 6601))
(def socket2 (create-udp-server 6602))
;; Start a receiving loop for each node, handle-message
;; does pattern matching on the received messages and
;; dispatches accordingly.
(def fut1 (receive socket1 (empty-packet 512) node1 handle-message))
(def fut2 (receive socket2 (empty-packet 512) node2 handle-message))
;; Send a heartbeat every 30 seconds to all nodes in
;; each node's partial-view
(schedule-heartbeat-send socket1 node1 (* 1000 60 5))
(schedule-heartbeat-send socket2 node2 (* 1000 60 5))
;; Decrease the heartbeat-counter of each node
;; every 5 minutes.
(schedule-heartbeat-dec socket1 node1 (* 1000 60 5))
(schedule-heartbeat-dec socket2 node2 (* 1000 60 5))
;; 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](./LICENSE)