<div dir="ltr">Hi Frans,<div><br></div><div>Here are a few comments with the caveat that I haven't spent any time understanding the protocol. So the comments are more about implementation style...</div><div><br></div><div>- Firstly, its quite impressive you've managed to write this in quite an idiomatic style for your hobby project, so well done!</div><div>- You might want to consider naming all your modules with the 'axolotl_' prefix to minimise the possibility of module name clashes when others use your code</div><div>- It would be a good idea to put all your DB access operations in a module such as axolotl_db.erl so that if you ever wanted to changed your database backend, the changes are limited to one module. It might not be that important for this particular application, but as rule of thumb it will serve you well.</div><div>- You raise a good question about "... decide what goes into a new process or is done in the calling process...". I'll try and clarify this with an example. You have implemented identities:check_registration/2 as a gen_server:call, but the code which handles this message in the handle_call function is just reading from mnesia and returning a result. This need not be a gen_server:call, it can be written as follows.</div><div><br></div><div><span class="" style="color:rgb(121,93,163);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16px;white-space:pre">check</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16px;white-space:pre">(</span><span class="" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16px;white-space:pre">Registration_id</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16px;white-space:pre">, </span><span class="" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16px;white-space:pre">Dhi_pub</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16px;white-space:pre">) </span><span class="" style="color:rgb(167,29,93);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16px;white-space:pre">-></span><br></div><div><div>    case mnesia:dirty_read(identity, Dhi_pub) of</div><div>        [#identity{registration_id = Registration_id}] -></div><div><span class="" style="white-space:pre">            </span>true;</div><div>        _ -></div><div><span class="" style="white-space:pre">            </span>false</div><div>    end.</div></div><div><br></div><div>This is because there is no value in putting it through the gen_server. It still makes sense for the code to reside in this module as it logically belongs here.</div><div><br></div><div>- Typically with Erlang applications, your mnesia initialisation code should be separate from your normal running code. It is okay to expect the user to run a one off installation function to create the required tables. Also, it is not a good idea to delete schema and recreate it because it becomes hard to use this as part of a node with other applications which have their own mnesia tables.</div><div><br></div><div>- The code in prekeys.erl is a bit hard to read. You might want to move the code from each of the handle_call function clauses into separate functions which are invoked. This is probably partly due to my ignorance of the protocol, but the code could be made to look cleaner.</div><div><br></div><div>- I couldn't see any test code in the modules, how are you testing this?</div><div><br></div><div>I hope this is of some help.</div><div><br></div><div>cheers,</div><div>Chandru</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 24 November 2015 at 18:18, Frans Schneider <span dir="ltr"><<a href="mailto:schneider@xs4all.nl" target="_blank">schneider@xs4all.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  

    
  
  <div text="#000000" bgcolor="#FFFFFF">
    Dear list,<br>
    <br>
    I've been learning Erlang in my spare-time for some time now and
    would love some feedback on a project I recently started. Since I
    have no coworkers or other people to get feedback from, maybe
    somebody on this list could have a quick look. <br>
    The things I find particular difficult is defining a proper API, to
    decide what goes into a new process or is done in the calling
    process and dealing with errors. I have no formal training as a
    programmer which may be the reason I have trouble to get these
    things right.<br>
    <br>
    The project I took [1] was to implement the Axolotl ratcheting
    protocol from Open Whisper Systems [2]. The protocol [3] itself
    didn't look very difficult, but since there are no proper specs for
    the total system, I used the libaxolotl-java implementation as a
    starting pont [4]. Reading the Java code probably was the hardest
    part of the whole project.<br>
    <br>
    I think I covered most of the functionality of the libaxolotl-java
    library. I haven't verified interoperability between my
    implementation and libaxolotl-java since that would require me to
    start coding in Java which is not something I am looking forward to.<br>
    Comparing my Erlang code with the original Java code, I needed far
    less lines of code and, I think, the code is much easier to
    understand. Also, building and deploying the code seems much
    simpler. <br>
    <br>
    So, any comments are most welcome.<br>
    <br>
    Thanks,<br>
    <br>
    Frans<br>
    <br>
    [1] <a href="https://github.com/schnef/axolotl" target="_blank">https://github.com/schnef/axolotl</a><br>
    [2] <a href="https://www.whispersystems.org/" target="_blank">https://www.whispersystems.org/</a><br>
    [3] <a href="https://github.com/trevp/axolotl/wiki" target="_blank">https://github.com/trevp/axolotl/wiki</a><br>
    [4] <a href="https://github.com/WhisperSystems/libaxolotl-java" target="_blank">https://github.com/WhisperSystems/libaxolotl-java</a><br>
    Nice implementation <a href="https://github.com/rxcomm/pyaxo" target="_blank">https://github.com/rxcomm/pyaxo</a><br>
    
  </div>

<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>