Beispiel #1
0
'use strict';

import React, {PropTypes} from 'react';
import ListForm from "components/generics/ListForm";
import Logger from 'logplease'

const logger = Logger.create('IpfsAddressSettings', { color: Logger.Colors.Red });

class IpfsAddressSettings extends React.Component {

  constructor(props) {
    super(props);
    this.onAddressChange = this.onAddressChange.bind(this);
    this.onInputChange = this.onInputChange.bind(this);
  }

  onAddressChange(value, name) {
    logger.info('change', name, value)
    let newAddress = Object.assign({}, this.props.Addresses)
    newAddress[name] = value
    this.props.onChange(newAddress, 'Addresses')
  }

  onInputChange(e) {
    this.onAddressChange(e.target.value, e.target.name);
  }

  render() {
    const Addresses = this.props.Addresses ? this.props.Addresses : {};
    const swarm = Addresses.Swarm ? Addresses.Swarm : []
    return (
Beispiel #2
0
'use strict'

import Reflux from 'reflux'
import OrbitStore from 'stores/OrbitStore'
import NetworkActions from 'actions/NetworkActions'
import Logger from 'logplease'

const logger = Logger.create('UserStore', { color: Logger.Colors.Green })

var UserStore = Reflux.createStore({
  listenables: [NetworkActions],
  init: function() {
    this.user = null
    OrbitStore.listen((orbit) => {
      orbit.events.on('connected', (network, user) => {
        logger.info(`Connected as ${user}`)
        this._update(user)
      })
    })
  },
  onDisconnect: function() {
    this._update(null)
  },
  _update: function(user) {
    logger.debug(`User updated: ${user}`)
    this.user = user

    if(!this.user)
      logger.debug("Not logged in!")

    this.trigger(this.user)
Beispiel #3
0
'use strict';

import _ from 'lodash';
import Reflux from 'reflux';
import AppActions from 'actions/AppActions';
import UIActions from 'actions/UIActions';
import NetworkActions from 'actions/NetworkActions';
import ChannelActions from 'actions/ChannelActions';
import SocketActions from 'actions/SocketActions';
import NotificationActions from 'actions/NotificationActions';
import UserActions from 'actions/UserActions';
import ChannelStore from 'stores/ChannelStore';
import UserStore from 'stores/UserStore';
import Logger from 'logplease';
const logger = Logger.create('MessageStore', { color: Logger.Colors.Magenta });

const messagesBatchSize = 8;

const MessageStore = Reflux.createStore({
  listenables: [AppActions, UIActions, NetworkActions, SocketActions, ChannelActions],
  init: function() {
    this.currentChannel = null;
    this.channels = {};
    this.posts = {}; // simple cache for message contents
    this._reset();

    // debug for Friedel
    window.send = (amount, interval) => {
      let i = 0;
      let timer = setInterval(() => {
        this.onSendMessage(this.currentChannel, "hello " + i);
Beispiel #4
0
'use strict';

import Reflux from 'reflux';
import SocketActions from 'actions/SocketActions';
import NetworkActions from 'actions/NetworkActions';
import ApiUrl from 'utils/apiurl';
import Logger from 'logplease';
const logger = Logger.create('ConnectionsStore', { color: Logger.Colors.Black });

var ConnectionStore = Reflux.createStore({
  init: function() {
    this.socket = null;

    // this.socket = io(ApiUrl.getSocketUrl(), {
    //   reconnectionDelay: 0,
    //   reconnectionDelayMax: 1000
    // });

    // this.socket.on('connect', () => {
    //   logger.debug("WebSocket connected");

    //   this.socket.on('network', (network) => {
    //     NetworkActions.updateNetwork(network);
    //   });

    //   SocketActions.socketConnected(this.socket);
    // });

    // this.socket.on('disconnect', () => {
    //   logger.debug("WebSocket disconnected");
    //   this.socket.removeAllListeners('network');
Beispiel #5
0
'use strict'

import IPFS from 'ipfs-daemon/src/ipfs-browser-daemon'
import _ from 'lodash'
import Reflux from 'reflux'
import Logger from 'logplease'
import path from 'path'
import AppActions from 'actions/AppActions'
import NetworkActions from 'actions/NetworkActions'
import IpfsDaemonActions from 'actions/IpfsDaemonActions'
import {defaultIpfsDaemonSettings} from '../config/ipfs-daemon.config'
import {defaultOrbitSettings} from '../config/orbit.config'

const logger = Logger.create('IpfsDaemonStore', { color: Logger.Colors.Green })
// const LOCAL_STORAGE_KEY = 'ipfs-daemon-settings'

var IpfsDaemonStore = Reflux.createStore({
  listenables: [AppActions, IpfsDaemonActions, NetworkActions],
  init: function() {
    logger.info('IpfsDaemonStore Init sequence')

    this.isElectron = window.isElectron
    this.ipfs = null
    this.ipfsDaemonSettings = {}
    this.settings = {}

    let orbitDataDir = window.orbitDataDir || '/orbit'
    let ipfsDataDir = window.ipfsDataDir   || '/orbit/ipfs'
    let settings = [defaultIpfsDaemonSettings(ipfsDataDir), defaultOrbitSettings(orbitDataDir)]
    // const persistedSettings = this.getIpfsSettings()
    // if (persistedSettings) {
Beispiel #6
0
import 'normalize.css';
import '../styles/main.css';
import 'styles/App.scss';
import 'styles/Scrollbars.scss';
import 'highlight.js/styles/hybrid.css';

const views = {
  "Index": "/",
  "Settings": "/settings",
  "Swarm": "/swarm",
  "Connect": "/connect",
  "Channel": "/channel/"
};

const logger = Logger.create('App', { color: Logger.Colors.Red });

var App = React.createClass({
  // mixins: [History],
  getInitialState: function() {
    return {
      panelOpen: false,
      user: null,
      location: null,
      joiningToChannel: null,
      requirePassword: false,
      theme: null,
      networkName: "Unknown Network"
    };
  },
  componentDidMount: function() {
Beispiel #7
0
var express = require('express');
function log (req, res) {
  console.log(['[', new Date().toISOString(), '] ', req.method, ' request from ', req.ip].join(''));
}
var bodyParser = require('body-parser');
var pug = require('pug');
var app = express();
var counter = 0;

var logplease = require('logplease');
var logger = logplease.create('express', { color: logplease.Colors.yellow });

app.use(bodyParser.urlencoded({ extended: true }));

var indexpug = pug.compileFile("index.pug");

app.get('/', function(req, res) {
  logger.info(`${req.method} from ${req.ip}`);
  log(req, res);
  res.send(indexpug({ counter: counter, lastinc: 1, msg: '', err: false }));
});

app.post('/inc', function(req, res) {
  log(req, res);
  var msg = null;
  var err = false;
  var lastinc = 0;
  if (req.body && req.body.incval) {
    var trimed = req.body.incval.replace(/(^\s*)|(\s*$)/g, '');
    if (err = !/^-?[0-9]+(\.[0-9]*)?$/.test(trimed))
      msg = ['"', lastinc = trimed, "' cannnot be parsed to numerical data." ].join('');
Beispiel #8
0
'use strict'

import Reflux from 'reflux'
import AppActions from 'actions/AppActions'
import NetworkActions from 'actions/NetworkActions'
import ChannelActions from 'actions/ChannelActions'
import AppStateStore from 'stores/AppStateStore'
import Logger from 'logplease'

const logger = Logger.create('ChannelStore', { color: Logger.Colors.Blue })

const ChannelStore = Reflux.createStore({
  listenables: [AppActions, NetworkActions, ChannelActions],
  init: function() {
    this.channels = []
  },
  onInitialize: function(orbit) {
    this.orbit = orbit
  },
  // TODO: remove this function once nobody's using it anymore
  get: function(channel) {
    return this.channels[channel]
  },
  onDisconnect: function() {
    this.channels = []
    this.trigger(this.channels)
  },
  onJoinChannel: function(channel, password) {
    // TODO: check if still needed?
    if(channel === AppStateStore.state.currentChannel)
      return
Beispiel #9
0
const main   = require('./src/main');

const Logger = require('logplease');
const logger = Logger.create("Orbit.Index");
Logger.setLogfile('debug.log');

(() => {
  main.start().then((events) => logger.info("Systems started"));
})();
Beispiel #10
0
'use strict'

import React from 'react'
import last from 'lodash.last'
import Message from 'components/Message'
import Message2 from 'components/Message2'
import ChannelControls from 'components/ChannelControls'
import NewMessageNotification from 'components/NewMessageNotification'
import Dropzone from 'react-dropzone'
import MessageStore from 'stores/MessageStore'
import UIActions from 'actions/UIActions'
import ChannelActions from 'actions/ChannelActions'
import Profile from "components/Profile"
import 'styles/Channel.scss'
import Logger from 'logplease'
const logger = Logger.create('Channel', { color: Logger.Colors.Cyan })

class Channel extends React.Component {
  constructor(props) {
    super(props)

    this.state = {
      peers: 0,
      channelChanged: true,
      channelName: null,
      messages: [],
      loading: false,
      loadingText: 'Connecting...',
      reachedChannelStart: false,
      channelMode: "Public",
      error: null,
Beispiel #11
0
'use strict';

const fs           = require('fs');
const path         = require('path');
const EventEmitter = require('events').EventEmitter;
const Logger       = require('logplease');
const logger       = Logger.create("Orbit.Main", { color: Logger.Colors.Yellow });
const utils        = require('../../src/utils');
const Orbit        = require('../../src/Orbit');
const IPFS         = require('exports?Ipfs!ipfs/dist/index.js')

var ENV = process.env["ENV"] || "release";
logger.debug("Running in '" + ENV + "' mode");
// process.env.PATH += ":/usr/local/bin" // fix for Electron app release bug (PATH doesn't get carried over)

// Create data directory
const dataPath = path.join(utils.getAppPath(), "/data");
// if(!fs.existsSync(dataPath))
//   fs.mkdirSync(dataPath);

/* MAIN */
const events = new EventEmitter();
let ipfs, orbit, peerId;

const start = exports.start = (ipfsApiInstance, repositoryPath, signalServerAddress) => {
  // if(!id) id = 0;//new Date().getTime();
  if(ipfsApiInstance) {
    // const i = new window.IpfsApi();
    // const i = new IPFAPI();
    orbit = new Orbit(ipfsApiInstance, { dataPath: dataPath });
    return ipfsApiInstance.id()
Beispiel #12
0
'use strict';

const _         = require('lodash')
const OrbitDB   = require('orbit-db');
const Post      = require('ipfs-post');
const IPFS      = require('ipfs')
const multiaddr = require('multiaddr')
const Logger    = require('logplease');
const logger    = Logger.create("send-message", { color: Logger.Colors.Yellow });
const utils     = require('../src/utils');

var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  // terminal: false
});

// usage: send-message.js <username> <channel> <message>
const network = 'QmaAHGFm78eupEaDFzBfhUL5xn32dbeqn8oU2XCZJTQGBj'; // 'localhost:3333'
const username = process.argv[2] ? process.argv[2] : 'testrunner';
const password = '';
const channelName = process.argv[3] ? process.argv[3] : 'c1';
const message = process.argv[4] ? process.argv[4] : 'hello world';

const startIpfs = () => {
  return new Promise((resolve, reject) => {
    const ipfs = new IPFS()
    ipfs.goOnline(() => {
      resolve(ipfs)
    })
Beispiel #13
0
'use strict'

const path = require('path')

const Logger = require('logplease')
const logger = Logger.create('cache', { color: Logger.Colors.Magenta })
Logger.setLogLevel('ERROR')

let caches = {}

class Cache {
  constructor (storage, directory) {
    this.path = directory || './orbitdb'
    this._storage = storage
    this._store = null
  }

  // Setup storage backend
  async open () {
    logger.debug('open', this.path)

    if (this.store)
      return Promise.resolve()

    return new Promise((resolve, reject) => {
      const store = this._storage(this.path)
      store.open((err) => {
        if (err) {
          return reject(err)
        }
        this._store = store
Beispiel #14
0
const fs = require('fs');
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
const Logplease = require('logplease');
const logger = Logplease.create('mongodb', { color: Logplease.Colors.Yellow }); 
const stringify = require('object-stringify');

const mongoUser = "******";
const mongoPassword = "******";
const mongoUrl = "mongodb://mongo.local:27017/test?ssl=true";
const certFile = fs.readFileSync("./mongodb-cert.crt");

var db;
var collection;

logger.info("Connecting...");
MongoClient.connect(mongoUrl, { server: { sslCA: certFile } }, mongoConnected);

function mongoConnected(error, connectedDatabase) {
  assert.equal(null, error);
  logger.info("Successfully connected.");
  logger.info("Authenticating...");
  db = connectedDatabase;
  db.authenticate(mongoUser, mongoPassword, mongoAuthenticated);
}

function mongoAuthenticated(error, result) {
  assert.equal(null, error);
  assert.equal(true, result);
  logger.info("Successfully authenticated.");
  logger.info("Finding document...");