Permalink
Browse files

first import from private repository

  • Loading branch information...
1 parent f0a51b6 commit 43f2a5e1d4498b62bb1c568d47cea7f4fb3e7879 Roberto De Ioris committed Jul 19, 2012
Showing with 3,582 additions and 0 deletions.
  1. +2 −0 Makefile
  2. +112 −0 blastbeat.h
  3. +13 −0 blastbeat.ini
  4. +23 −0 http-parser/LICENSE-MIT
  5. +2,059 −0 http-parser/http_parser.c
  6. +318 −0 http-parser/http_parser.h
  7. +243 −0 src/config.c
  8. +154 −0 src/http.c
  9. +452 −0 src/main.c
  10. +206 −0 src/websocket.c
View
@@ -0,0 +1,2 @@
+all:
+ gcc -g -o blastbeat src/main.c src/config.c src/http.c src/websocket.c http-parser/http_parser.c -lzmq -lssl -lcrypto -lev
View
@@ -0,0 +1,112 @@
+#include <ev.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include "http-parser/http_parser.h"
+#include <zmq.h>
+#include <openssl/sha.h>
+#include <openssl/bio.h>
+#include <openssl/buffer.h>
+#include <openssl/evp.h>
+#include <sys/resource.h>
+
+#define MAX_HEADERS 100
+
+#define MAX_CHUNK_STORAGE ((sizeof("18446744073709551616") * 2) + 3)
+#ifndef ULLONG_MAX
+# define ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */
+#endif
+#define ntohll(y) (((uint64_t)ntohl(y)) << 32 | ntohl(y>>32))
+#define htonll(y) (((uint64_t)htonl(y)) << 32 | htonl(y>>32))
+
+
+#define BLASTBEAT_TYPE_WEBSOCKET 1
+
+struct bb_dealer {
+ char *identity;
+ size_t len;
+ char *identify_prefix;
+ time_t last_pong;
+ struct bb_dealer *next;
+};
+
+struct bb_pinger {
+ ev_timer pinger;
+ struct bb_virtualhost *vhost;
+};
+
+struct bb_virtualhost {
+ char *name;
+ size_t len;
+ struct bb_pinger pinger;
+ struct bb_dealer *dealers;
+ struct bb_virtualhost *next;
+};
+
+struct bb_http_header {
+ char *key;
+ size_t keylen;
+ char *value;
+ size_t vallen;
+};
+
+struct bb_session;
+
+struct bb_session_request {
+ struct bb_session *bbs;
+ http_parser parser;
+ off_t header_pos;
+ int last_was_value;
+ int close;
+ int type;
+ uint64_t content_length;
+ uint64_t written_bytes;
+ char *websocket_message_queue;
+ uint64_t websocket_message_queue_len;
+ uint64_t websocket_message_queue_pos;
+ uint8_t websocket_message_phase;
+ uint8_t websocket_message_has_mask;
+ //char websocket_message_mask[4];
+ uint64_t websocket_message_size;
+ struct bb_http_header headers[MAX_HEADERS];
+ struct bb_session_request *next;
+};
+
+struct bb_session {
+ int fd;
+ ev_io read_event;
+ int new_request;
+ struct bb_dealer *dealer;
+ struct bb_session_request *requests_head;
+ struct bb_session_request *requests_tail;
+};
+
+struct blastbeat_server {
+ char *addr;
+ unsigned short port;
+ char *zmq;
+
+ float ping_freq;
+
+ void *router;
+ int zmq_fd;
+ struct ev_loop *loop;
+
+ struct bb_session **fd_table;
+ int max_fd;
+
+ ev_io event_accept;
+ ev_io event_zmq;
+
+ struct bb_virtualhost *vhosts;
+};
+
+
+void bb_error(char *);
+struct bb_http_header *bb_http_req_header(struct bb_session_request *, char *, size_t);
+struct bb_dealer *bb_get_dealer(char *, size_t);
View
@@ -0,0 +1,13 @@
+[blastbeat]
+bind = 0.0.0.0:8080
+zmq = tcp://192.168.173.5:5000
+ping-freq = 3
+uid = 1000
+gid = 1000
+daemon = 1
+
+[blastbeat:quantal64.local:8080]
+node = FOOBAR1
+
+[blastbeat:localhost]
+node = FOOBAR1
View
@@ -0,0 +1,23 @@
+http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright
+Igor Sysoev.
+
+Additional changes are licensed under the same terms as NGINX and
+copyright Joyent, Inc. and other Node contributors. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
Oops, something went wrong.

0 comments on commit 43f2a5e

Please sign in to comment.