Skip to content

Instantly share code, notes, and snippets.

@hintjens
hintjens / gist:5480625
Last active February 19, 2022 04:51
Hello World HTTP server using ZeroMQ * Build and install libzmq and CZMQ * Full article on http://hintjens.com/blog:42
// Minimal HTTP server in 0MQ
#include "czmq.h"
int main (void)
{
zctx_t *ctx = zctx_new ();
void *router = zsocket_new (ctx, ZMQ_ROUTER);
zsocket_set_router_raw (router, 1);
int rc = zsocket_bind (router, "tcp://*:8080");
assert (rc != -1);
@hintjens
hintjens / dechat.c
Created April 22, 2013 11:05
Decentralized chat app in C (40 lines)
#include <czmq.h>
static void
listener_thread (void *args, zctx_t *ctx, void *pipe)
{
void *listener = zsocket_new (ctx, ZMQ_SUB);
zsocket_set_subscribe (listener, "");
int address;
for (address = 1; address < 255; address++)
@hintjens
hintjens / gist:5411950
Last active December 16, 2015 09:19
Can You Crack It? - Secure messaging for the Internet
The ZeroMQ messaging library spawned a new product category of thin,
fast message transports that today includes JeroMQ, NullMQ, NetMQ,
Axon, Crossroads, Nanomsg, and more. Fast, light messaging on the LAN
is now a solved problem. But how about Internet scale? That means
security. Pieter Hintjens explains how he remixed D.J.Bernstein's
NaCl and CurveCP with SASL (IETF RFC 4422) to create a new ZeroMQ
protocol (ZMTP 3.0) and security handshake (CurveZMQ). This focus of
this talk will be on the design choices in ZMTP and CurveZMQ, and how
different kinds of architecture need different types of security.
@hintjens
hintjens / census1.c
Created March 26, 2013 19:08
Census pattern
// The Census Pattern
// Model 1, over XPUB-XSUB
#include "czmq.h"
static void
counter_task (void *args, zctx_t *ctx, void *pipe)
{
void *counter = zsocket_new (ctx, ZMQ_XPUB);
zsocket_set_xpub_verbose (counter, 1);
// The Meerkat Pattern
//
// In which we address the slow subscriber problem by asking for
// a show of hands before we start publishing.
#include "czmq.h"
static void
publisher_task (void *args, zctx_t *ctx, void *pipe)
{
@hintjens
hintjens / zcurve.c
Last active December 15, 2015 07:39
CurveZMQ prototype - see http://hintjens.com/blog:36 for the story.
/* =========================================================================
CurveZMQ - authentication and confidentiality for 0MQ
-------------------------------------------------------------------------
Copyright (c) 1991-2013 iMatix Corporation <www.imatix.com>
Copyright other contributors as noted in the AUTHORS file.
This is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
@hintjens
hintjens / c
Created March 12, 2013 10:28
C helper script, old iMatix magic
#! /bin/sh
#
# c - C compile command
#
# Copyright (c) 1996-2009 iMatix Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
@hintjens
hintjens / zcurve-poc.c
Last active May 23, 2016 00:41
zcurve -- CurveCP over ZeroMQ -- proof of concept
// Proof of concept CurveCP handshake over 0MQ.
//
// Demonstrates a confidential, authenticated connection between
// two 0MQ peers (two DEALER sockets in this example). See the
// curvecp.org website for details of the security design.
//
// This is a flat walk-through in code with minimal abstraction.
// The next version of this code will be more packaged.
//
// IMPORTANT NOTE: this code has not been reviewed by security experts
@hintjens
hintjens / nacl_performance.c
Created March 11, 2013 20:55
Simple performance test of NaCl (requires CZMQ) - placed into the public domain
// Exploring functionality of NaCl
#include <czmq.h>
#include <crypto_box.h>
#include <crypto_secretbox.h>
#include <randombytes.h>
int main (void)
{
// Generate public+secret key pair
#include "czmq.h"
static void
s_test_attached (void *args, zctx_t *ctx, void *pipe)
{
while (true) {
void *dealer = zsocket_new (ctx, ZMQ_DEALER);
if (!dealer)
break;
zsocket_connect (dealer, "tcp://localhost:9999");