{"size": 2139, "ext": "js", "max_stars_repo_path": "examples/p2p_demo/peer_demo.js", "max_stars_repo_name": "digicert/web-of-things-framework", "max_stars_repo_stars_event_min_datetime": "2015-06-01T14:09:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-20T06:17:58.000Z", "max_issues_repo_path": "examples/p2p_demo/peer_demo.js", "max_issues_repo_name": "digicert/web-of-things-framework", "max_issues_repo_issues_event_min_datetime": "2015-06-01T14:09:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-15T19:41:47.000Z", "max_forks_repo_path": "examples/p2p_demo/peer_demo.js", "max_forks_repo_name": "digicert/web-of-things-framework", "max_forks_repo_forks_event_min_datetime": "2015-06-01T13:09:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T18:23:25.000Z"}
{"max_stars_count": 234, "max_issues_count": 51, "max_forks_count": 86, "avg_line_length": 28.52, "max_line_length": 137, "alphanum_fraction": 0.4932211314}
﻿var PeerNetwork = require('../../libs/transport/p2p/wotkad/peer_network');
var logger = require('../../logger');

var peernet = new PeerNetwork();

// create the overlay network with node1
var options = {
    address: '127.0.0.1',
    port: 65529,
    nick: 'seed1'
};
var seed1 = peernet.create_peer(options);

options = {
    address: '127.0.0.1',
    port: 65530,
    nick: 'seed2',
    seeds: [{ address: '127.0.0.1', port: 65529 }]
};
var seed2 = peernet.create_peer(options);

// connect to the overlay network
options = {
    address: '127.0.0.1',
    port: 65531,
    nick: 'node2',
    seeds: [{ address: '127.0.0.1', port: 65529 }]
};
var peer2 = peernet.create_peer(options);

options = {
    address: '127.0.0.1',
    port: 65532,
    nick: 'node3',
    seeds: [{ address: '127.0.0.1', port: 65530 }]
};
var peer3 = peernet.create_peer(options);

peer2.on('connect', function (err, value) {
    if (err) {
        return logger.error("peer connect error %j", err, {});
    }
    
    logger.debug("peer peer2 %j connected to overlay network", value, {});

    peer2.put('door12/events/bell', 'beep1 from peer2', function (err) {
        if (err) {
            return logger.error("onPut error %j", err, {});
        }
        
    });

});

peer3.on('connect', function (err, value) {
    if (err) {
        return logger.error("peer connect error %j", err, {});    
    }

    logger.debug("peer peer3 %j connected to overlay network", value, {});
    
    peernet.on('data', function (key) {
        if (key == 'door12/events/bell') {
            peer3.get('door12/events/bell', function (err, value) {
                if (err) {
                    return logger.error("peer get error %j", err, {});
                }
                logger.debug('--------------------------------------------------------------------------------------------------------');
                logger.debug('peer3 received door12/events/bell value is : ' + value);
                logger.debug('--------------------------------------------------------------------------------------------------------');
            });
        }
    });
    
});