tristanls / discover

Node discovery based on Kademlia DHT protocol.
MIT License
69 stars 10 forks source link

discover.register(contact) API forces breaking encapsulation #5

Closed tristanls closed 10 years ago

tristanls commented 10 years ago

Requiring contact.transport when registering a contact (as shown below) violates encapsulation when Discover is used by another library. The below excerpt from tristanls/tart-ansible/index.js#L59 illustrates the problem:

    var registerDomain = function registerDomain(domainName, receptionist) {
        var data = {};
        Object.keys(transports).forEach(function (scheme) {
            data[scheme] = transports[scheme].data;
        });
        var contact = {
            id: domainName,
            data: data,
            transport: {
                host: discover.transport.host, // <- reaching all up in discover's pockets
                port: discover.transport.port
            }
        };
        domains[domainName] = receptionist;
        discover.register(contact);
    };
tristanls commented 10 years ago

In order to fix this, we need contact.transport to be optional (or preferably even disallowed) when calling discover.register(contact).

tristanls commented 10 years ago

Implementation of tcpTransport.setTransportInfo(contact) now enables Discover to add correct transport data to contact's upon registration.

tristanls commented 10 years ago

Resolved as of afe5f84509e36964522823a503015320b4acb7a1