sync removal test branch sync_removal DO NOT USE
authorKrista Bennett <krista@pep-project.org>
Fri, 03 Nov 2017 12:36:55 +0100
branchsync_removal
changeset 17265196feaf8bf
parent 171 7b87d09a0f06
child 173 57f17e3c8ac1
sync removal test branch
src/message.cc
src/message_api.cc
src/message_api.hh
src/pEpmodule.cc
test/multipEp.py
     1.1 --- a/src/message.cc	Sun Oct 01 18:14:00 2017 +0200
     1.2 +++ b/src/message.cc	Fri Nov 03 12:36:55 2017 +0100
     1.3 @@ -111,10 +111,7 @@
     1.4          {
     1.5              if (encoding == "") {
     1.6                  string _mime_type = _bl->mime_type ? _bl->mime_type : "";
     1.7 -                if (_mime_type == "application/pEp.sync")
     1.8 -                    encoding = "pep.sync";
     1.9 -                else
    1.10 -                    encoding = "ascii";
    1.11 +                encoding = "ascii";
    1.12              }
    1.13              object codecs = import("codecs");
    1.14              object _decode = codecs.attr("decode");
    1.15 @@ -387,4 +384,3 @@
    1.16          }
    1.17      }
    1.18  }
    1.19 -
     2.1 --- a/src/message_api.cc	Sun Oct 01 18:14:00 2017 +0200
     2.2 +++ b/src/message_api.cc	Fri Nov 03 12:36:55 2017 +0100
     2.3 @@ -1,7 +1,7 @@
     2.4  #include "message_api.hh"
     2.5  #include <pEp/pEpEngine.h>
     2.6  #include <pEp/message_api.h>
     2.7 -#include <pEp/sync.h>
     2.8 +//#include <pEp/sync.h>
     2.9  
    2.10  namespace pEp {
    2.11      namespace PythonAdapter {
    2.12 @@ -65,58 +65,57 @@
    2.13              return (int) ::color_from_rating((PEP_rating) rating);
    2.14          }
    2.15  
    2.16 -        void _config_keep_sync_msg(bool enabled)
    2.17 -        {
    2.18 -            ::config_keep_sync_msg(session, enabled);
    2.19 -        }
    2.20 +        // void _config_keep_sync_msg(bool enabled)
    2.21 +        // {
    2.22 +        //     ::config_keep_sync_msg(session, enabled);
    2.23 +        // }
    2.24  
    2.25 -        boost::python::tuple sync_decode(object buffer)
    2.26 -        {
    2.27 -            Py_buffer src;
    2.28 -            int result = PyObject_GetBuffer(buffer.ptr(), &src, PyBUF_CONTIG_RO);
    2.29 -            if (result)
    2.30 -                throw invalid_argument("need a contiguous buffer to read");
    2.31 +        // boost::python::tuple sync_decode(object buffer)
    2.32 +        // {
    2.33 +        //     Py_buffer src;
    2.34 +        //     int result = PyObject_GetBuffer(buffer.ptr(), &src, PyBUF_CONTIG_RO);
    2.35 +        //     if (result)
    2.36 +        //         throw invalid_argument("need a contiguous buffer to read");
    2.37 +        // 
    2.38 +        //     char *dst = NULL;
    2.39 +        //     PEP_STATUS status = decode_sync_msg((char *) src.buf, src.len, &dst);
    2.40 +        //     PyBuffer_Release(&src);
    2.41 +        //     _throw_status(status);
    2.42 +        // 
    2.43 +        //     string _dst(dst);
    2.44 +        //     free(dst);
    2.45 +        //     return boost::python::make_tuple(_dst, 0);
    2.46 +        // }
    2.47  
    2.48 -            char *dst = NULL;
    2.49 -            PEP_STATUS status = decode_sync_msg((char *) src.buf, src.len, &dst);
    2.50 -            PyBuffer_Release(&src);
    2.51 -            _throw_status(status);
    2.52 +        // static boost::python::tuple sync_encode(string text)
    2.53 +        // {
    2.54 +        //     char *data = NULL;
    2.55 +        //     size_t size = 0;
    2.56 +        //     PEP_STATUS status = encode_sync_msg(text.c_str(), &data, &size);
    2.57 +        //     _throw_status(status);
    2.58 +        // 
    2.59 +        //     PyObject *ba = PyBytes_FromStringAndSize(data, size);
    2.60 +        //     free(data);
    2.61 +        //     if (!ba)
    2.62 +        //         throw bad_alloc();
    2.63 +        // 
    2.64 +        //     return boost::python::make_tuple(object(handle<>(ba)), 0);
    2.65 +        // }
    2.66  
    2.67 -            string _dst(dst);
    2.68 -            free(dst);
    2.69 -            return boost::python::make_tuple(_dst, 0);
    2.70 -        }
    2.71 -
    2.72 -        static boost::python::tuple sync_encode(string text)
    2.73 -        {
    2.74 -            char *data = NULL;
    2.75 -            size_t size = 0;
    2.76 -            PEP_STATUS status = encode_sync_msg(text.c_str(), &data, &size);
    2.77 -            _throw_status(status);
    2.78 -
    2.79 -            PyObject *ba = PyBytes_FromStringAndSize(data, size);
    2.80 -            free(data);
    2.81 -            if (!ba)
    2.82 -                throw bad_alloc();
    2.83 -
    2.84 -            return boost::python::make_tuple(object(handle<>(ba)), 0);
    2.85 -        }
    2.86 -
    2.87 -        object sync_search(string name)
    2.88 -        {
    2.89 -            if (name != "pep.sync") {
    2.90 -                return object();
    2.91 -            }
    2.92 -            else {
    2.93 -                object codecs = import("codecs");
    2.94 -                object CodecInfo = codecs.attr("CodecInfo");
    2.95 -
    2.96 -                object _sync_decode = make_function(sync_decode);
    2.97 -                object _sync_encode = make_function(sync_encode);
    2.98 -
    2.99 -                return call< object >(CodecInfo.ptr(), _sync_encode, _sync_decode);
   2.100 -            }
   2.101 -        }
   2.102 +        // object sync_search(string name)
   2.103 +        // {
   2.104 +        //     if (name != "pep.sync") {
   2.105 +        //         return object();
   2.106 +        //     }
   2.107 +        //     else {
   2.108 +        //         object codecs = import("codecs");
   2.109 +        //         object CodecInfo = codecs.attr("CodecInfo");
   2.110 +        // 
   2.111 +        //         object _sync_decode = make_function(sync_decode);
   2.112 +        //         object _sync_encode = make_function(sync_encode);
   2.113 +        // 
   2.114 +        //         return call< object >(CodecInfo.ptr(), _sync_encode, _sync_decode);
   2.115 +        //     }
   2.116 +        // }
   2.117      }
   2.118  }
   2.119 -
     3.1 --- a/src/message_api.hh	Sun Oct 01 18:14:00 2017 +0200
     3.2 +++ b/src/message_api.hh	Fri Nov 03 12:36:55 2017 +0100
     3.3 @@ -8,8 +8,7 @@
     3.4                  int enc_format = 4, int flags = 0);
     3.5          boost::python::tuple decrypt_message(Message src);
     3.6          int _color(int rating);
     3.7 -        void _config_keep_sync_msg(bool enabled);
     3.8 -        object sync_search(string name);
     3.9 +//        void _config_keep_sync_msg(bool enabled);
    3.10 +//        object sync_search(string name);
    3.11      }
    3.12  }
    3.13 -
     4.1 --- a/src/pEpmodule.cc	Sun Oct 01 18:14:00 2017 +0200
     4.2 +++ b/src/pEpmodule.cc	Fri Nov 03 12:36:55 2017 +0100
     4.3 @@ -5,12 +5,11 @@
     4.4  #include <iomanip>
     4.5  #include "basic_api.hh"
     4.6  #include "message_api.hh"
     4.7 -#include "sync_mixin.hh"
     4.8 +//#include "sync_mixin.hh"
     4.9  
    4.10  #include <mutex>
    4.11  
    4.12  #include <pEp/message_api.h>
    4.13 -#include <pEp/sync.h>
    4.14  
    4.15  namespace pEp {
    4.16      namespace PythonAdapter {
    4.17 @@ -142,7 +141,7 @@
    4.18      "\n"
    4.19      "decode Blob data into string depending on MIME type if encoding=''\n"
    4.20      "\n"
    4.21 -    "   mime_type='application/pEp.sync'    decode as 'pEp.sync'\n"
    4.22 +    "   mime_type='application/pEp.sync'    decode as 'pEp.sync' (OBSOLETE - DO NOT USE)\n"
    4.23      "   other mime_type                     decode as 'ascii' by default\n"
    4.24                  )
    4.25          .add_property("mime_type", (string(Message::Blob::*)()) &Message::Blob::mime_type,
    4.26 @@ -261,7 +260,7 @@
    4.27      "   msg             the decrypted p≡p message\n"
    4.28      "   keys            a list of keys being used\n"
    4.29      "   rating          the rating of the message as integer\n"
    4.30 -    "   consumed        boolean denoting message is consumed by sync\n"
    4.31 +    "   consumed        boolean denoting message is consumed by sync. NOTE: DEPRECATED\n"
    4.32      "   flags           flags set while decryption (reserved)\n"
    4.33                  )
    4.34          .add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have")
    4.35 @@ -342,91 +341,6 @@
    4.36      "text = trustwords(ident_own, ident_partner)\n"
    4.37      "\n"
    4.38      "calculate trustwords for two Identities");
    4.39 -    def("config_keep_sync_msg", &_config_keep_sync_msg,
    4.40 -    "config_keep_sync_msg(enabled)\n"
    4.41 -    "\n"
    4.42 -    "configure if sync messages are being kept or automatically removed (default)");
    4.43 -
    4.44 -    // key sync API
    4.45 -
    4.46 -    enum_<sync_handshake_signal>("sync_handshake_signal")
    4.47 -        .value("SYNC_NOTIFY_UNDEFINED"             , SYNC_NOTIFY_UNDEFINED)
    4.48 -        .value("SYNC_NOTIFY_INIT_ADD_OUR_DEVICE"   , SYNC_NOTIFY_INIT_ADD_OUR_DEVICE)
    4.49 -        .value("SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE" , SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE)
    4.50 -        .value("SYNC_NOTIFY_INIT_FORM_GROUP"       , SYNC_NOTIFY_INIT_FORM_GROUP)
    4.51 -        .value("SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE"  , SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE)
    4.52 -        .value("SYNC_NOTIFY_TIMEOUT"               , SYNC_NOTIFY_TIMEOUT)
    4.53 -        .value("SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED" , SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED)
    4.54 -        .value("SYNC_NOTIFY_ACCEPTED_GROUP_CREATED", SYNC_NOTIFY_ACCEPTED_GROUP_CREATED)
    4.55 -        .value("SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED" , SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED)
    4.56 -        .value("SYNC_NOTIFY_OVERTAKEN"             , SYNC_NOTIFY_OVERTAKEN);
    4.57 -
    4.58 -    auto sync_mixin_class = class_<SyncMixIn, SyncMixIn_callback, boost::noncopyable>(
    4.59 -            "SyncMixIn",
    4.60 -    "class MySyncHandler(SyncMixIn):\n"
    4.61 -    "   def messageToSend(self, msg):\n"
    4.62 -    "       ...\n"
    4.63 -    "\n"
    4.64 -    "   def notifyHandshake(self, me, partner):\n"
    4.65 -    "       ...\n"
    4.66 -    "\n"
    4.67 -    "   def setTimeout(self, timeout):\n"
    4.68 -    "       ...\n"
    4.69 -    "\n"
    4.70 -    "   def cancelTimeout(self):\n"
    4.71 -    "       ...\n"
    4.72 -    "\n"
    4.73 -    "p≡p Sync MixIn\n"
    4.74 -    "\n"
    4.75 -    "write a handler class to enable p≡p sync protocol\n")
    4.76 -        .def("messageToSend", &SyncMixIn::messageToSend,
    4.77 -    "messageToSend(self, msg)"
    4.78 -    "\n"
    4.79 -    "   msg             p≡p message to send\n"
    4.80 -    "\n"
    4.81 -    "overwrite this method with code actually sending msg")
    4.82 -        .def("notifyHandshake", &SyncMixIn::notifyHandshake,
    4.83 -    "notifyHandshake(self, me, partner)\n"
    4.84 -    "\n"
    4.85 -    "   me              own identity\n"
    4.86 -    "   partner         identity of communication partner\n"
    4.87 -    "\n"
    4.88 -    "overwrite this method with code showing a trustwords dialog")
    4.89 -#ifndef NDEBUG
    4.90 -        .def("inject", &SyncMixIn::_inject,
    4.91 -    "inject(self, event, partner, extra)\n"
    4.92 -    "\n"
    4.93 -    "   event           number of event to inject\n"
    4.94 -    "   partner         identity of communication partner\n"
    4.95 -    "   extra           optional extra data or None\n"
    4.96 -    "\n"
    4.97 -    "inject an event into the sync state machine (for debugging purposes only)")
    4.98 -#endif
    4.99 -        .def("deliverHandshakeResult", &SyncMixIn::deliverHandshakeResult,
   4.100 -    "deliverHandshakeResult(self, partber, result)\n"
   4.101 -    "\n"
   4.102 -    "   partner         identity of communication partner\n"
   4.103 -    "   result          -1: cancel, 0: accepted, 1: rejected\n"
   4.104 -    "\n"
   4.105 -    "call to deliver the handshake result")
   4.106 -        .def("setTimeout", &SyncMixIn::setTimeout,
   4.107 -    "setTimeout(self, timeout)\n"
   4.108 -    "\n"
   4.109 -    "   timeout         timeout to wait for\n"
   4.110 -    "\n"
   4.111 -    "overwrite this method with code setting timeout timer")
   4.112 -        .def("cancelTimeout", &SyncMixIn::cancelTimeout,
   4.113 -    "cancelTimeout(self)\n"
   4.114 -    "\n"
   4.115 -    "overwrite this method with code canceling timeout timer")
   4.116 -        .def("onTimeout", &SyncMixIn::onTimeout,
   4.117 -    "onTimeout(self)\n"
   4.118 -    "\n"
   4.119 -    "call this method when timeout occurs");
   4.120 -
   4.121 -    // codecs
   4.122 -
   4.123 -    call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search));
   4.124  
   4.125      // init() and release()
   4.126  
   4.127 @@ -442,4 +356,92 @@
   4.128          ss >> s;
   4.129          throw runtime_error(s);
   4.130      }
   4.131 +
   4.132 +    
   4.133 +    // def("config_keep_sync_msg", &_config_keep_sync_msg,
   4.134 +    // "config_keep_sync_msg(enabled)\n"
   4.135 +    // "\n"
   4.136 +    // "configure if sync messages are being kept or automatically removed (default)");
   4.137 +
   4.138 +    // key sync API
   4.139 +
   4.140 +//     enum_<sync_handshake_signal>("sync_handshake_signal")
   4.141 +//         .value("SYNC_NOTIFY_UNDEFINED"             , SYNC_NOTIFY_UNDEFINED)
   4.142 +//         .value("SYNC_NOTIFY_INIT_ADD_OUR_DEVICE"   , SYNC_NOTIFY_INIT_ADD_OUR_DEVICE)
   4.143 +//         .value("SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE" , SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE)
   4.144 +//         .value("SYNC_NOTIFY_INIT_FORM_GROUP"       , SYNC_NOTIFY_INIT_FORM_GROUP)
   4.145 +//         .value("SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE"  , SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE)
   4.146 +//         .value("SYNC_NOTIFY_TIMEOUT"               , SYNC_NOTIFY_TIMEOUT)
   4.147 +//         .value("SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED" , SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED)
   4.148 +//         .value("SYNC_NOTIFY_ACCEPTED_GROUP_CREATED", SYNC_NOTIFY_ACCEPTED_GROUP_CREATED)
   4.149 +//         .value("SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED" , SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED)
   4.150 +//         .value("SYNC_NOTIFY_OVERTAKEN"             , SYNC_NOTIFY_OVERTAKEN);
   4.151 +// 
   4.152 +//     auto sync_mixin_class = class_<SyncMixIn, SyncMixIn_callback, boost::noncopyable>(
   4.153 +//             "SyncMixIn",
   4.154 +//     "class MySyncHandler(SyncMixIn):\n"
   4.155 +//     "   def messageToSend(self, msg):\n"
   4.156 +//     "       ...\n"
   4.157 +//     "\n"
   4.158 +//     "   def notifyHandshake(self, me, partner):\n"
   4.159 +//     "       ...\n"
   4.160 +//     "\n"
   4.161 +//     "   def setTimeout(self, timeout):\n"
   4.162 +//     "       ...\n"
   4.163 +//     "\n"
   4.164 +//     "   def cancelTimeout(self):\n"
   4.165 +//     "       ...\n"
   4.166 +//     "\n"
   4.167 +//     "p≡p Sync MixIn\n"
   4.168 +//     "\n"
   4.169 +//     "write a handler class to enable p≡p sync protocol\n")
   4.170 +//         .def("messageToSend", &SyncMixIn::messageToSend,
   4.171 +//     "messageToSend(self, msg)"
   4.172 +//     "\n"
   4.173 +//     "   msg             p≡p message to send\n"
   4.174 +//     "\n"
   4.175 +//     "overwrite this method with code actually sending msg")
   4.176 +//         .def("notifyHandshake", &SyncMixIn::notifyHandshake,
   4.177 +//     "notifyHandshake(self, me, partner)\n"
   4.178 +//     "\n"
   4.179 +//     "   me              own identity\n"
   4.180 +//     "   partner         identity of communication partner\n"
   4.181 +//     "\n"
   4.182 +//     "overwrite this method with code showing a trustwords dialog")
   4.183 +// #ifndef NDEBUG
   4.184 +//         .def("inject", &SyncMixIn::_inject,
   4.185 +//     "inject(self, event, partner, extra)\n"
   4.186 +//     "\n"
   4.187 +//     "   event           number of event to inject\n"
   4.188 +//     "   partner         identity of communication partner\n"
   4.189 +//     "   extra           optional extra data or None\n"
   4.190 +//     "\n"
   4.191 +//     "inject an event into the sync state machine (for debugging purposes only)")
   4.192 +// #endif
   4.193 +//         .def("deliverHandshakeResult", &SyncMixIn::deliverHandshakeResult,
   4.194 +//     "deliverHandshakeResult(self, partber, result)\n"
   4.195 +//     "\n"
   4.196 +//     "   partner         identity of communication partner\n"
   4.197 +//     "   result          -1: cancel, 0: accepted, 1: rejected\n"
   4.198 +//     "\n"
   4.199 +//     "call to deliver the handshake result")
   4.200 +//         .def("setTimeout", &SyncMixIn::setTimeout,
   4.201 +//     "setTimeout(self, timeout)\n"
   4.202 +//     "\n"
   4.203 +//     "   timeout         timeout to wait for\n"
   4.204 +//     "\n"
   4.205 +//     "overwrite this method with code setting timeout timer")
   4.206 +//         .def("cancelTimeout", &SyncMixIn::cancelTimeout,
   4.207 +//     "cancelTimeout(self)\n"
   4.208 +//     "\n"
   4.209 +//     "overwrite this method with code canceling timeout timer")
   4.210 +//         .def("onTimeout", &SyncMixIn::onTimeout,
   4.211 +//     "onTimeout(self)\n"
   4.212 +//     "\n"
   4.213 +//     "call this method when timeout occurs");
   4.214 +
   4.215 +    // codecs
   4.216 +
   4.217 +//    call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search));
   4.218 +
   4.219  }
     5.1 --- a/test/multipEp.py	Sun Oct 01 18:14:00 2017 +0200
     5.2 +++ b/test/multipEp.py	Fri Nov 03 12:36:55 2017 +0100
     5.3 @@ -67,7 +67,7 @@
     5.4  msgs_folders = None
     5.5  
     5.6  # both side globals (not managed)
     5.7 -disable_sync = False
     5.8 +disable_sync = True 
     5.9  
    5.10  # ----------------------------------------------------------------------------
    5.11  #                               INSTANCE ACTIONS