From 033e026b508d8461f3b43b4d2934fc95ce695a99 Mon Sep 17 00:00:00 2001 From: aspect Date: Fri, 6 Feb 2015 02:11:40 -0500 Subject: [PATCH] Fixing IP under nginx problem --- config/testnet.cfg | 2 +- testnet.js | 24 +++++++++++++++++++----- views/index.ejs | 4 ++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/config/testnet.cfg b/config/testnet.cfg index f03399f..343d5f3 100644 --- a/config/testnet.cfg +++ b/config/testnet.cfg @@ -1,5 +1,5 @@ { - http_port : 80, // http interface port + http_port : 2752, // http interface port daemon_poll_freq : 5000, // how often to poll daemon for status updates http_poll_freq : 2000, // how often should http client poll server for status updates diff --git a/testnet.js b/testnet.js index 28119fa..8f5b053 100644 --- a/testnet.js +++ b/testnet.js @@ -9,10 +9,21 @@ var JSON = require("json"), colors = require('colors'), wallet_interface = require('bitcoin'); +var RESET_TIME = 1000*60*60*24*2; + var limits = { } +resetLimits(); + + +function dpc(t,fn) { if(typeof(t) == 'function') setTimeout(t,0); else setTimeout(fn,t); } + +function resetLimits() { + limits = { } + dpc(RESET_TIME, resetLimits); +} function get_client_ip(req) { - var ipAddress; + var ipAddress = null; // Amazon EC2 / Heroku workaround to get real client IP var forwardedIpsStr = req.header('x-forwarded-for'); if (forwardedIpsStr) { @@ -22,6 +33,9 @@ function get_client_ip(req) { var forwardedIps = forwardedIpsStr.split(','); ipAddress = forwardedIps[0]; } + + ipAddress = req.header('X-Real-IP'); + if (!ipAddress) { // Ensure getting client IP address still works in // development environment @@ -30,9 +44,6 @@ function get_client_ip(req) { return ipAddress; }; - -function dpc(t,fn) { if(typeof(t) == 'function') setTimeout(t,0); else setTimeout(fn,t); } - // Read config from the config folder. This function will check for 'name.hostname.cfg' // and if not present, it will read 'name.cfg'. This allows user to create a custom // local config file without distrupting the main config. @@ -95,7 +106,7 @@ function Application() { var ip = get_client_ip(req); - var limit = 1000; + var limit = 10; var amount = parseFloat(req.query.amount); if(amount > limit) @@ -108,6 +119,9 @@ function Application() { if(to_send + limits[ip] > limit) to_send = limit - limits[ip]; +// console.log("ip:",ip,"limit:",limit,"limits[ip]:",limits[ip],"to_send:",to_send); +// console.log("req.connection",req); + if(to_send <= 0) return res.end(JSON.stringify({ error : 'maximum amount exceeded, already sent '+limits[ip]+' coins'})); diff --git a/views/index.ejs b/views/index.ejs index d3575cf..cab56ee 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -58,7 +58,7 @@ function Application() { // --- _.each(response.last_blocks, function(o) { - str += ""+o.height+" - "+o.hash+"
"; + str += ""+o.height+" - "+o.hash+"
"; }); $("#last_blocks").html(str); @@ -124,7 +124,7 @@ BALANCE (1 confirms):
SEND -Limit: 1000 coins per IP.
+Limit: 10 coins per IP.
TO ADDRESS: AMOUNT: