seems like it should set the local value but it isn't #2

Closed
shimondoodkin opened this Issue Jun 22, 2014 · 20 comments

3 participants

@shimondoodkin
Collaborator

seems like it should set the local value but it isn't so i wrote this so it will set the local value. not sure if i fixed it right in the way this library works .

a.on('set', function (peer, k, v,expiresAt) {
    //
       //a.my_state.max_version_seen += 1;
       //a.my_state.setKey(k, v, a.my_state.max_version_seen, expiresAt);
        if(a.get(k)!=v)
        {
             a.my_state.updateLocal(k, v, expiresAt);
              //  if(a.my_state.attrs[k])   a.my_state.attrs[k][0] =v;
         //else                           a.my_state.attrs[k] = [v, a.my_state.max_version_seen, expiresAt];
     }
        console.log(this.peer_name + " knows via on('set'.. that peer " + peer + " set " + k + "=" + v);
    });

it could be added here i think:
https://github.com/automenta/telepathine/blob/master/lib/telepathine.js#L244

@shimondoodkin
Collaborator

so how does this works? so there will be a shared state.

seems this fix is working for me

@kessler
Collaborator

Great that it works for you however it is not sufficient.

You could, for example, connect all nodes to each other and have them broadcast every time a value is changed and it will still work for you but it will not be gossip and it will perform badly especially in scenarios where gossip protocols come in.

One of the the basic principles of the protocol is that it keep incrementing version, this version is used whenever two nodes converse.

I suggest that if you choose to change core code of something you should at least get to know the basics of the thing you are changing.

@shimondoodkin
Collaborator

i understand, i have changed the function , tested it and it seems working. everybody knows what everybody knows.
https://gist.github.com/shimondoodkin/825eb6f4d84a224f4df5

the replication is very slow

@shimondoodkin
Collaborator

no, it is not working. when i plug it in, to my application
with a.my_state.updateLocal(k, v, expiresAt); for some reason i get infinite loop.

@automenta
Owner

hi @shimondoodkin thanks for testing this. i think what you're trying to do is what's provided by the 'believe' method. see if example_believe.js is what you want. it sets the local variable to the received value of another peer. in other words, it tells the peer to "believe" what another peer is telling it. otherwise it is free to set its own value in the local store for that key. @kessler is probably right about unintended network consequences so i'd recommend being careful with the "believe" method, i'll label it as experimental for now.

https://github.com/automenta/telepathine/blob/master/lib/telepathine.js#L323

@shimondoodkin
Collaborator

i suggest making the on set:* to have hame arguments as on set
https://github.com/automenta/telepathine/blob/master/lib/telepathine.js#L635
and using the key from it in believe
https://github.com/automenta/telepathine/blob/master/lib/telepathine.js#L325
it will enable to do

a.believe('*', function (peer,k, v,expiresAt) {
        console.log(peer  + " after believe of "+k+ ' with value '+v);
        console.log('a me '+a.peer_name + " get somekey=" + a.get('somekey'),' ~=',v,'peer=',peer,a.peers[peer]?a.getRemote(peer, k):'no remote');
    });
@automenta
Owner

@shimondoodkin seems like a good change. do you want to update the code or should i? the example_believe.js will need updated also

@shimondoodkin
Collaborator

do it

@automenta
Owner

not sure when i'm going to be able to make this and the other changes. if you'd like to, please go ahead. do you have any specific application for telepathine that you're planning?

@shimondoodkin
Collaborator

ok

@shimondoodkin
Collaborator

this is my sample program
https://gist.github.com/shimondoodkin/bcb72bd5be9661fe9906

for some reason believe does not work from the beginning. the events are not emitted
so i made a "hack" (exe cuted the beleive on update directly) look here
https://gist.github.com/shimondoodkin/bcb72bd5be9661fe9906#file-telepathine-js-L647
and here
https://gist.github.com/shimondoodkin/bcb72bd5be9661fe9906#file-telepathine-js-L326

@shimondoodkin shimondoodkin reopened this Jun 24, 2014
@shimondoodkin
Collaborator

i wrote what i do here: dominictarr/scuttlebutt#35 (comment)
a data collection application. i need it redundant so it will never need to be stopped.
i use p2p for self assembly of the network.

i will not write many of updates to telepathine (maybe while using). i just need to have work done. i share what i fix on my way.

i think i will keep using telepathine for now or maybe for ever, but i wish telepathine had is noticed disconnects in real time. like tcp client/server.on.close/end and use tcp ip keepalive. i thought maybe to develop my p2p module that is a full p2p network like every node connected to every. but i afraid of unknown and while i can i will use telepathine to be be able continue my work.

by emitting "bye" event seems it notices disconnect in timely manner, but it requires to emit it. kind of work for me.

@automenta
Owner

ok, can you take example_believe and create example_believe2 which demonstrates the bug, or if you fixed it, shows that it works? i'm not sure of the timing when your functions call. if it's a simple example which does not involve ZMQ i can debug it easier.

yes i agree to prevent believe of say events. good find

there are parameters that will affect when peers notice others disconnect (the accrual failure detection) but an emitted 'bye' event will be the fastest. is that merged into the code? it would be helpful

@automenta
Owner

if you can put all of the event handlers in the 'start' even handler, like in example_believe.js, it should work.

https://github.com/automenta/telepathine/blob/master/simulation/example_believe.js#L22

after() and every() add to the 'start' handler also:
https://github.com/automenta/telepathine/blob/master/lib/telepathine.js#L344

this is because the start() function is responsible for the initial 'set' handler which many others depend on:
https://github.com/automenta/telepathine/blob/master/lib/telepathine.js#L243

i'll see if i can rewrite your code in a gist.

@automenta
Owner

https://gist.github.com/automenta/1290581b6bb7ee637af2#file-zmq-js-L235

if that still doesnt work, try calling start() before .on('start') like in example_believe.js
https://github.com/automenta/telepathine/blob/master/simulation/example_believe.js#L22

is there a better way to setup these events?

@shimondoodkin
Collaborator

found it i had ":" in key name

@automenta
Owner

maybe we can "escape" key names that contain colons. i'll add an issue for this, though it's not high priority. good find

@shimondoodkin
Collaborator

in eventemitter2 it is possible to use array instead of colon string.

@shimondoodkin
Collaborator

yes low priority, not need now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment