GithubHelp home page GithubHelp logo

dht's People

Contributors

ahf avatar arcusfelis avatar beapirate avatar benoitc avatar dewolfe avatar eryx67 avatar jlouis avatar mads-hartmann avatar zert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dht's Issues

Wrong data is being sent on the socket

For some reason, the socket is sending the wrong data. The following is the counterexample which should be studied. Chances are this is a model error.

(x1).........xxxxxx(144 times)
0
{{state,[#{hi => 128,lo => 0,nodes => [],split => true}],false,0,[],[]},
 {state,0,false,#Fun<dht_routing_table_eqc.0.26523270>,#{}},
 {state,false,0}}
[{init,
  {[{dht_state_eqc,{state,false,0}},
    {dht_net_eqc,{state,false,1729,[],[]}},
    {dht_store_eqc,{state,[],false}},
    {dht_routing_meta_eqc,
     {state,[#{hi => 128,lo => 0,nodes => [],split => true}],false,0,[],[]}},
    {dht_routing_table_eqc,
     {state,0,false,#Fun<dht_routing_table_eqc.0.26523270>,#{}}},
    {dht_time_eqc,{state,0,[],0}}],
   [{blocked_calls,[]},
    {fresh_id,1},
    {workers,[]},
    {command_timeout,{var,command_timeout}},
    {async_timeout,{var,async_timeout}},
    {meta_cmd_stack,[]}]}},
 {set,
  {var,1},
  {call,dht_state_eqc,start_link,
   [0,[]],
   [{id,1},
    {self,{var,{pid,root}}},
    {res,true},
    {callouts,
     {seq,
      {res,
       {internal,dht_routing_table_eqc,new,
        [0,0,128],
        [{id,1},{self,{var,{pid,root}}}],
        empty},
       'ROUTING_TABLE'},
      {seq,
       [{internal,dht_routing_meta_eqc,new,
         ['ROUTING_TABLE'],
         [{id,1},{self,{var,{pid,root}}}],
         {seq,
          [empty,
           {seq,
            {res,
             {internal,dht_time_eqc,monotonic_time,[],
              [{id,1},{self,{var,{pid,root}}}],
              {seq,[{callout,dht_time,monotonic_time,[],0},{return,0}]}},
             0},
            {seq,
             [{internal,dht_routing_table_eqc,node_list,
               ['ROUTING_TABLE'],
               [{id,1},{self,{var,{pid,root}}}],
               empty},
              {seq,
               [{internal,dht_routing_table_eqc,node_id,
                 ['ROUTING_TABLE'],
                 [{id,1},{self,{var,{pid,root}}}],
                 empty},
                {seq,
                 [{seq,
                   [{internal,dht_routing_table_eqc,ranges,
                     ['_'],
                     [{id,1},{self,{var,{pid,root}}}],
                     empty},
                    {seq,
                     {res,
                      {internal,dht_time_eqc,monotonic_time,[],
                       [{id,1},{self,{var,{pid,root}}}],
                       {seq,
                        [{callout,dht_time,monotonic_time,[],0},{return,0}]}},
                      0},
                     {seq,
                      [{seq,
                        [{callout,dht_time,convert_time_unit,
                          [0,native,milli_seconds],
                          0},
                         {return,0}]},
                       {seq,
                        {res,
                         {internal,dht_time_eqc,send_after,
                          [900000,<0.20836.0>,{inactive_range,{0,128}}],
                          [{id,1},{self,{var,{pid,root}}}],
                          {seq,
                           [{callout,dht_time,send_after,
                             [900000,'_',{inactive_range,{0,128}}],
                             {tref,0}},
                            {return,{tref,0}}]}},
                         {tref,0}},
                        {internal,dht_routing_meta_eqc,add_timer_for_range,
                         [{0,128},{tref,0}],
                         [{id,1},{self,{var,{pid,root}}}],
                         empty}}]}}]},
                  {seq,
                   [{internal,dht_routing_meta_eqc,init_nodes,
                     [[],0],
                     [{id,1},{self,{var,{pid,root}}}],
                     {seq,
                      [{callout,dht_time,convert_time_unit,
                        [900000,milli_seconds,native],
                        900000},
                       {return,900000}]}},
                    {return,{ok,0,'ROUTING_TABLE'}}]}]}]}]}}]}},
        {seq,[{seq,[]},{return,true}]}]}}}]}},
 {set,
  {var,2},
  {call,dht_store_eqc,start_link,[],
   [{id,2},
    {self,{var,{pid,root}}},
    {res,ok},
    {callouts,
     {seq,
      [{internal,dht_time_eqc,send_after,
        [300000,dht_store,evict],
        [{id,2},{self,{var,{pid,root}}}],
        {seq,
         [{callout,dht_time,send_after,[300000,'_',evict],{tref,1}},
          {return,{tref,1}}]}},
       {return,ok}]}}]}},
 {set,
  {var,3},
  {call,dht_net_eqc,init,
   [0,[<<0,0,0,0,0,0,0,0>>,<<0,0,0,0,0,0,0,0>>]],
   [{id,4},
    {self,{var,{pid,root}}},
    {res,true},
    {callouts,
     {seq,
      [empty,
       {seq,
        [{callout,dht_socket,open,[0,'_'],{ok,'SOCKET_REF'}},
         {seq,
          [{internal,dht_time_eqc,send_after,
            [300000,dht_net,renew_token],
            [{id,4},{self,{var,{pid,root}}}],
            {seq,
             [{callout,dht_time,send_after,[300000,'_',renew_token],{tref,2}},
              {return,{tref,2}}]}},
           {return,true}]}]}]}}]}},
 {set,
  {var,4},
  {call,dht_net_eqc,find_value,
   [{{0,0,0,0},0},0],
   [{id,14},
    {self,{var,{pid,14}}},
    {res,{'$eqc_block',{var,{pid,14}}}},
    {callouts,
     {seq,
      {res,
       {seq,
        [{val,0,
          {internal,dht_state_eqc,node_id,[],
           [{id,14},{self,{var,{pid,14}}}],
           {return,0}}},
         {seq,
          {res,{val,1,{callout,dht_rand,uniform,[65535],1}},1},
          {seq,
           {res,
            {val,ok,
             {callout,dht_socket,send,['SOCKET_REF',{0,0,0,0},0,'_'],ok}},
            ok},
           {seq,
            {res,
             {internal,dht_time_eqc,send_after,
              [2000,dht_net,{request_timeout,{{{0,0,0,0},0},<<0,1>>}}],
              [{id,14},{self,{var,{pid,14}}}],
              {seq,
               [{callout,dht_time,send_after,
                 [2000,'_',{request_timeout,{{{0,0,0,0},0},<<0,1>>}}],
                 {tref,3}},
                {return,{tref,3}}]}},
             {tref,3}},
            {seq,
             [{internal,dht_net_eqc,add_blocked,
               [{var,{pid,14}},
                {request,{tref,3},{{0,0,0,0},0},1,{find,value,0}}],
               [{id,14},{self,{var,{pid,14}}}],
               empty},
              {seq,{res,{'$eqc_block',{var,{pid,14}}},no_res},empty}]}}}}]},
       no_res},
      empty}}]}},
 {set,
  {var,5},
  {call,dht_net_eqc,store,
   [{{0,0,0,0},0},<<0,0,0,0,0,0,0,0>>,0,0],
   [{id,31},
    {self,{var,{pid,31}}},
    {res,{'$eqc_block',{var,{pid,31}}}},
    {callouts,
     {seq,
      {res,
       {seq,
        [{val,0,
          {internal,dht_state_eqc,node_id,[],
           [{id,31},{self,{var,{pid,31}}}],
           {return,0}}},
         {seq,
          {res,{val,1,{callout,dht_rand,uniform,[65535],1}},1},
          {seq,
           {res,
            {val,ok,
             {callout,dht_socket,send,['SOCKET_REF',{0,0,0,0},0,'_'],ok}},
            ok},
           {seq,
            {res,
             {internal,dht_time_eqc,send_after,
              [2000,dht_net,{request_timeout,{{{0,0,0,0},0},<<0,1>>}}],
              [{id,31},{self,{var,{pid,31}}}],
              {seq,
               [{callout,dht_time,send_after,
                 [2000,'_',{request_timeout,{{{0,0,0,0},0},<<0,1>>}}],
                 {tref,4}},
                {return,{tref,4}}]}},
             {tref,4}},
            {seq,
             [{internal,dht_net_eqc,add_blocked,
               [{var,{pid,31}},
                {request,
                 {tref,4},
                 {{0,0,0,0},0},
                 1,
                 {store,<<0,0,0,0,0,0,0,0>>,0,0}}],
               [{id,31},{self,{var,{pid,31}}}],
               empty},
              {seq,{res,{'$eqc_block',{var,{pid,31}}},no_res},empty}]}}}}]},
       no_res},
      empty}}]}}]

dht_state_eqc:start_link(0, []) ->
  0 = dht_time:monotonic_time(),
  0 = dht_time:monotonic_time(),
  0 = dht_time:convert_time_unit(0, native, milli_seconds),
  {tref, 0} = dht_time:send_after(900000, <0.4713.1>, {inactive_range, {0, 128}}),
  900000 = dht_time:convert_time_unit(900000, milli_seconds, native),
  true.
dht_store_eqc:start_link() ->
  {tref, 1} = dht_time:send_after(300000, dht_store, evict),
  ok.
dht_net_eqc:init(0,
    [<<0, 0, 0, 0, 0, 0, 0, 0>>, <<0, 0, 0, 0, 0, 0, 0, 0>>]) ->
  {ok, 'SOCKET_REF'} = dht_socket:open(0, [binary, inet, {active, 16}]),
  {tref, 2} = dht_time:send_after(300000, dht_net, renew_token),
  true.
%% self = <0.4716.1>
dht_net_eqc:find_value({{0, 0, 0, 0}, 0}, 0) ->
  1 = dht_rand:uniform(65535),
  ok = dht_socket:send('SOCKET_REF', {0, 0, 0, 0}, 0,
           [<<175, 64, 13, 52, 167, 136, 55, 45, 0, 1, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0>>,
            113,
            <<102, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>]),
  {tref, 3} = dht_time:send_after(2000, dht_net,
                  {request_timeout, {{{0, 0, 0, 0}, 0}, <<0, 1>>}}),
  ?BLOCK(<0.4716.1>).
%% self = <0.4717.1>
dht_net_eqc:store({{0, 0, 0, 0}, 0}, <<0, 0, 0, 0, 0, 0, 0, 0>>, 0, 0) ->
  1 = dht_rand:uniform(65535),
  exit({mocking_error, unexpected}) = dht_rand:uniform(65535),
  ?BLOCK(<0.4717.1>).

Reason:
  Post-condition failed:
  Callout mismatch:
    unexpected: dht_rand:uniform(65535)
    expected: dht_socket:send('SOCKET_REF', {0, 0, 0, 0}, 0, _)
  Unexpected unblock:
    dht_net_eqc:find_value({{0, 0, 0, 0}, 0}, 0) ->
      exit({{{{mocking_error, {unexpected, dht_rand:uniform(65535)}},
              [{eqc_mocking, f6141523_0, [dht_rand, uniform, [65535]],
                  [{file, "../src/eqc_mocking.erl"}, {line, 401}]},
               {eqc_mocking, do_action, 3,
                  [{file, "../src/eqc_mocking.erl"}, {line, 397}]},
               {dht_net, unique_message_id, 3,
                  [{file,
                      "/home/jlouis/Store/P/dht/_build/default/lib/dht/src/dht_net.erl"},
                   {line, 362}]},
               {dht_net, send_query, 4,
                  [{file,
                      "/home/jlouis/Store/P/dht/_build/default/lib/dht/src/dht_net.erl"},
                   {line, 380}]},
               {dht_net, handle_call, 3,
                  [{file,
                      "/home/jlouis/Store/P/dht/_build/default/lib/dht/src/dht_net.erl"},
                   {line, 225}]},
               {gen_server, try_handle_call, 4,
                  [{file, "gen_server.erl"}, {line, 629}]},
               {gen_server, handle_msg, 5,
                  [{file, "gen_server.erl"}, {line, 661}]},
               {proc_lib, init_p_do_apply, 3,
                  [{file, "proc_lib.erl"}, {line, 240}]}]},
             {gen_server, call,
                [dht_net, {request, {{0, 0, 0, 0}, 0}, {find, value, 0}}]}},
            [{gen_server, call, 2, [{file, "gen_server.erl"}, {line, 204}]},
             {dht_net, find_value, 2,
                [{file,
                    "/home/jlouis/Store/P/dht/_build/default/lib/dht/src/dht_net.erl"},
                 {line, 148}]}]})
[prop_cluster_correct]

lookup for an ID assigned in 2 nodes is only returned once

Following our discussion on slack: The doc says:

Multiple peers can store the same identity. In that case, each peer is reflected in the table.

But when I run the following example on 3 nodes (started locally) I only get one result:

1) Launch 3 nodes:

node 1:

1>  application:load(dht),
1>  application:set_env(dht, port, 1729).
ok
2>  application:ensure_all_started(dht).
{ok,[crypto,dht]}

node 2:

1>  application:load(dht),
1>  application:set_env(dht, port, 1730).
ok
2>  application:ensure_all_started(dht).
{ok,[crypto,dht]}

node 3:

1>  application:load(dht),
1>  application:set_env(dht, port, 1731).
ok
2>  application:ensure_all_started(dht).
{ok,[crypto,dht]}

2) Then node 2 and node 3 join node 1:

node2 & node3:

3> dht:ping({{127, 0, 0, 1}, 1729}).
{ok,164275074679377439255457697552131619293959778100}

3) register the ID 456 on node 1 and node 2

node1:

4> dht:enter(456, 5000).

node2:

4> dht:enter(456, 3000).

4) running lookup on different nodes return:

node1:

5> dht:lookup(456).
[{{127,0,0,1},3000}]

node2 & node3:

 5> dht:lookup(456).
 [{{127,0,0,1},5000}]

Where I would have expected on each nodes [{{127,0,0,1},3000},{{127,0,0,1},5000}] .

Search can fail with a function_clause error

Code outside the EQC kernel might fail. This looks like a traditional bug

=ERROR REPORT==== 26-Sep-2015::22:55:20 ===
** Generic server dht_track terminating 
** Last message in was {refresh,456,3000}
** When Server state == {state,#{456 => 3000}}
** Reason for termination == 
** {function_clause,
       [{dht_search,accum_results,
            [[{{36204707630545954172038695459673098801770676921,
                {192,168,1,105},
                3723},
               {error,timeout}}]],
            [{file,
                 "/export/home/jlouis/P/dht/_build/default/lib/dht/src/dht_search.erl"},
             {line,120}]},
        {dht_search,accum_peers,3,
            [{file,
                 "/export/home/jlouis/P/dht/_build/default/lib/dht/src/dht_search.erl"},
             {line,117}]},
        {dht_search,track_state,3,
            [{file,
                 "/export/home/jlouis/P/dht/_build/default/lib/dht/src/dht_search.erl"},
             {line,91}]},
        {dht_search,dht_iter_search,6,
            [{file,
                 "/export/home/jlouis/P/dht/_build/default/lib/dht/src/dht_search.erl"},
             {line,58}]},
        {dht_track,refresh,2,
            [{file,
                 "/export/home/jlouis/P/dht/_build/default/lib/dht/src/dht_track.erl"},
             {line,105}]},
        {dht_track,handle_info,2,
            [{file,
                 "/export/home/jlouis/P/dht/_build/default/lib/dht/src/dht_track.erl"},
             {line,88}]},
        {gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,615}]},
        {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,681}]}]}

Invert the call path in request_success verification

Ok, dht_net is sitting and calling dht_state. Then the dht_state code delivers a message back to dht_net. It is much easier to just return a value and then do stuff based on this.

It will solve many troublesome parts of races.

When refreshing a node, the DHT network stack deadlocks

First, the error report, then the explanation:

=ERROR REPORT==== 15-Aug-2015::23:18:22 ===
** Generic server dht_net terminating 
** Last message in was {udp,'SOCKET_REF',
                            {165,9981,16961,47768,50511,56659,47148,46353},
                            50662,
                            <<175,64,13,52,167,136,55,45,196,185,0,0,0,0,0,0,
                              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                              0,7,114,112>>}
** When Server state == {state,'SOCKET_REF',
                               #{{{{0,0,0,0},0},<<0,1>>} => {{<0.5497.0>,#Ref<0.0.2.58709>},{tref,3}},
                                 {{{215,166,165,189},62174},<<139,148>>} => {{<0.5499.0>,#Ref<0.0.2.58747>},{tref,6}},
                                 {{{165,9981,16961,47768,50511,56659,47148,
                                    46353},
                                   50662},
                                  <<"Ĺ">>} => {{<0.5504.0>,#Ref<0.0.2.58915>},{tref,14}}},
                               {[<<0,0,0,0,0,0,0,0>>],[<<0,0,0,0,0,0,0,0>>]}}
** Reason for termination == 
** {{timeout,{gen_server,call,
                         [dht_net,
                          {request,{{60522,46801,463,33476,34447,62268,2848,
                                     41219},
                                    58448},
                                   ping}]}},
    [{gen_server,call,2,[{file,"gen_server.erl"},{line,204}]},
     {dht_net,ping,1,
              [{file,"/home/jlouis/Store/P/dht/_build/default/lib/dht/src/dht_net.erl"},
               {line,101}]},
     {dht_state,refresh_node,1,
                [{file,"/home/jlouis/Store/P/dht/_build/default/lib/dht/src/dht_state.erl"},
                 {line,164}]},
     {dht_state,request_success,2,
                [{file,"/home/jlouis/Store/P/dht/_build/default/lib/dht/src/dht_state.erl"},
                 {line,141}]},
     {dht_net,handle_packet,3,
              [{file,"/home/jlouis/Store/P/dht/_build/default/lib/dht/src/dht_net.erl"},
               {line,311}]},
     {dht_net,handle_info,2,
              [{file,"/home/jlouis/Store/P/dht/_build/default/lib/dht/src/dht_net.erl"},
               {line,250}]},
     {gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,615}]},
     {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,681}]}]}

Whenever a peer is found, a call is made to the state system in order to figure out the node state of the possibly new peer. If this happens on a full bucket, we need to verify peers. This invokes a call to the network system.

But if the caller is the network system, currently executing, then it is not possible to call yourself, which will happen and then the system deadlocks.

The solution is to make verification asynchronous. Send a message to the network stack and let it handle that message instead. Add special provision for these messages as being "ping verifications". Once such a message completes, the underlying insert is part of it and will be retried.

The state system becomes much simpler since the code base doesn't have to worry about retries anymore. And the network stack doesn't become much more complex since it already has 99% of all the pieces in place.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.