Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first import from private repository
- Loading branch information
Roberto De Ioris
committed
Jul 19, 2012
1 parent
f0a51b6
commit 43f2a5e
Showing
10 changed files
with
3,582 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.