Skip to content

Commit

Permalink
Fixing IP under nginx problem
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Feb 6, 2015
1 parent f090c78 commit 033e026
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/testnet.cfg
Original file line number Diff line number Diff line change
@@ -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

Expand Down
24 changes: 19 additions & 5 deletions testnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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'}));

Expand Down
4 changes: 2 additions & 2 deletions views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function Application() {
// ---
_.each(response.last_blocks, function(o) {
str += "<a href='http://testnet.litecointools.com:2750/block/"+o.hash+"' target='_blank'>"+o.height+" - "+o.hash+" <img src='link.gif'/></a><br/>";
str += "<a href='http://explorer.litecointools.com/block/"+o.hash+"' target='_blank'>"+o.height+" - "+o.hash+" <img src='link.gif'/></a><br/>";
});
$("#last_blocks").html(str);
Expand Down Expand Up @@ -124,7 +124,7 @@ BALANCE (1 confirms): <span id='balance_1'></span>
</fieldset>
<br/>
<fieldset><legend>SEND</legend>
Limit: 1000 coins per IP.<br/>
Limit: 10 coins per IP.<br/>
TO ADDRESS: <input id='send_address' type='text' style='width:300px;'/>
AMOUNT: <input id='send_amount' type='text' />
<button id='send'>SEND</button>
Expand Down

0 comments on commit 033e026

Please sign in to comment.