Permalink
Browse files

adding redis to datastore #22

  • Loading branch information...
William
William committed May 23, 2018
1 parent 1018e9d commit cb6fbc56abc41d2da88425729fd3f7f627484441
Showing with 106 additions and 2 deletions.
  1. +3 −1 package.json
  2. +5 −1 src/config.js
  3. +49 −0 src/store/redis.js
  4. +49 −0 todo.md
View
@@ -15,6 +15,8 @@
"bencode": "^2.0.0",
"bitfield": "^2.0.0",
"knex": "^0.14.6",
"mongodb": "~3.0.8",
"redis": "^2.8.0",
"sqlite3": "^4.0.0"
},
"description": "AlphaReign Torrent Engine",
@@ -34,4 +36,4 @@
"start": "node src/index.js"
},
"version": "1.0.0"
}
}
View
@@ -5,12 +5,16 @@ const config = {
timeout: 5000,
},
mongodb: { url: 'mongodb://localhost:27017' },
redis: {
host: '127.0.0.1',
port: 6379,
},
sqlite: {
client: 'sqlite3',
connection: { filename: "./store/db.sqlite3" },
useNullAsDefault: true,
},
store: 'mongodb',
store: 'redis',
};
module.exports = config;
View
@@ -0,0 +1,49 @@
import config from './../config';
const redis = require("redis");
const client = redis.createClient(config.redis.port, config.redis.host);
client.on("error", (error) => {
throw new Error(error);
});
const redisCMD = (cmd, ...args) => (
new Promise((resolve, reject) => {
client[cmd](...args, (error, response) => (error ? reject(error) : resolve(response)));
})
);
export const upsert = async (torrent) => {
let record = {};
try {
const output = await redisCMD('get', torrent.infohash);
record = JSON.parse(output);
} catch (error) {
// Don't do anything
}
record = record || {};
record.created = record.created || Date.now();
record.update = Date.now();
record.infohash = torrent.infohash;
record.data = torrent;
await redisCMD('set', torrent.infohash, JSON.stringify(record));
};
export const count = async () => {
const output = await redisCMD('info', 'keyspace');
const countLine = output.split(`\n`).find((line) => line.indexOf('db0:') > -1);
const total = countLine.split(',')[0].replace('db0:keys=', '');
// console.log(output);
return total;
};
export default {
count,
upsert,
};
View
49 todo.md
@@ -0,0 +1,49 @@
# AlphaReign
The goal of AlphaRegin is create a piece of software that creates a network on top of the BitTorrent DHT Network. This extra network layer is meant negotiate the list of torrents that exists in the DHT Network. On top of that, it will provide a way to search through torrents
## AutoDiscovery of Torrents
This will be handled by the BitTorrent DHT Scraper here: https://github.com/AlphaReign/scraper
## AlphaReign Network
This is the network that lives on top of the BitTorrent DHT Network. It's goal is to share torrent hashes, torrent info and other nodes
### AR API
This is a working copy and may drastically change
* HTTPS GET /nodes - Returns a list of nodes
```
{
...payload,
payload: {
nodes: [
{
address: '255.255.255.255',
port: '80'
},
{
address: 'bootstrap.alphareign.com',
port: '80'
}
]
}
}
```
* HTTPS GET /hashes - Returns a list of torrent hashes
```
{
...payload,
payload: {
hashes: [
'e4be9e4db876e3e3179778b03e906297be5c8dbe',
'ddee5cb75c12f3165ef79a12a5cd6158bef029ad'
]
}
}
```
* HTTPS GET /hash/{infohash} - Returns torrent information

0 comments on commit cb6fbc5

Please sign in to comment.