Merge pull request #4 from avishkarabhishek786/master

manually tested and complete version
This commit is contained in:
Abhishek Sinha 2020-05-20 18:28:59 +05:30 committed by GitHub
commit 40bfad13a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 45444 additions and 34862 deletions

6
.gitignore vendored
View File

@ -1,4 +1,2 @@
examples.mk
json-rpc/
supernode/playground/
playground
supernode/

View File

@ -1,2 +1,6 @@
# localbitcoin++
A decentralized localbitcoin.com type Bitcoin trading platform.
<strong>IMPORTANT: This project is for educational purposes. Use of this software for commercial purpose is higly discouraged and shall be done on personal risk. The author shall not be deemed responsible for any profit or loss of any kind.</strong>
A distributed single HTML page Bitcoin trading platform. Based on pure Javascript, this single page HTML 5 Bitcoin trading exchange can be used to deposit, withdraw and trade Bitcoins removing need to download any app or software. Moreover, this application also removes any need of username and password verification.
The application is currently in beta phase.

14441
cash_payments_handler.html Normal file

File diff suppressed because it is too large Load Diff

30996
index.html Normal file

File diff suppressed because one or more lines are too long

16219
mongoose.c

File diff suppressed because it is too large Load Diff

6641
mongoose.h

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +0,0 @@
PROG = websocket_chat
MODULE_CFLAGS = -DMG_ENABLE_FILESYSTEM=1
include ../examples.mk

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,87 +0,0 @@
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#include "mongoose.h"
static sig_atomic_t s_signal_received = 0;
static const char *s_http_port = "9000";
static struct mg_serve_http_opts s_http_server_opts;
static void signal_handler(int sig_num) {
signal(sig_num, signal_handler); // Reinstantiate signal handler
s_signal_received = sig_num;
}
static int is_websocket(const struct mg_connection *nc) {
return nc->flags & MG_F_IS_WEBSOCKET;
}
static void broadcast(struct mg_connection *nc, const struct mg_str msg) {
struct mg_connection *c;
char buf[500];
char addr[32];
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
snprintf(buf, sizeof(buf), "%s %.*s", addr, (int) msg.len, msg.p);
printf("%s\n", buf); /* Local echo. */
for (c = mg_next(nc->mgr, NULL); c != NULL; c = mg_next(nc->mgr, c)) {
if (c == nc) continue; /* Don't send to the sender. */
mg_send_websocket_frame(c, WEBSOCKET_OP_TEXT, buf, strlen(buf)); // A single websocket frame is sent
}
}
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
switch (ev) {
case MG_EV_WEBSOCKET_HANDSHAKE_DONE: {
/* New websocket connection. Tell everybody. */
broadcast(nc, mg_mk_str("++ joined"));
break;
}
case MG_EV_WEBSOCKET_FRAME: {
struct websocket_message *wm = (struct websocket_message *) ev_data;
/* New websocket message. Tell everybody. */
struct mg_str d = {(char *) wm->data, wm->size}; //This is the data received data inside *ev_data
broadcast(nc, d); //Action when data is received
break;
}
case MG_EV_HTTP_REQUEST: {
mg_serve_http(nc, (struct http_message *) ev_data, s_http_server_opts);
break;
}
case MG_EV_CLOSE: {
/* Disconnect. Tell everybody. */
if (is_websocket(nc)) {
broadcast(nc, mg_mk_str("-- left"));
}
break;
}
}
}
int main(void) {
struct mg_mgr mgr;
struct mg_connection *nc;
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
setvbuf(stdout, NULL, _IOLBF, 0);
setvbuf(stderr, NULL, _IOLBF, 0);
mg_mgr_init(&mgr, NULL);
nc = mg_bind(&mgr, s_http_port, ev_handler); //connection mg_connection and manager mg_mgr are linked along with port and event handler
mg_set_protocol_http_websocket(nc);
s_http_server_opts.document_root = "."; // Serve current directory
s_http_server_opts.enable_directory_listing = "yes";
printf("Started on port %s\n", s_http_port);
while (s_signal_received == 0) {
mg_mgr_poll(&mgr, 200);
}
mg_mgr_free(&mgr);
return 0;
}