From 68620751d8d70cc9720b1188b9c74b853753d67f Mon Sep 17 00:00:00 2001
From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net>
Date: Fri, 18 Oct 2019 15:56:09 +0700
Subject: [PATCH] [*] Service order structures

---
 CMakeLists.txt             |  8 +++--
 dap_chain_net_srv.c        |  5 +--
 dap_chain_net_srv_common.h | 19 ++++++++---
 dap_chain_net_srv_order.c  | 65 ++++++++++++++++++++++++++++++++++++++
 dap_chain_net_srv_order.h  | 55 ++++++++++++++++++++++++++++++++
 5 files changed, 143 insertions(+), 9 deletions(-)
 create mode 100644 dap_chain_net_srv_order.c
 create mode 100644 dap_chain_net_srv_order.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 35d8ca6..54055ef 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,12 +2,14 @@ cmake_minimum_required(VERSION 2.8)
 project (dap_chain_net_srv)
   
 set(DAP_CHAIN_NET_SRV_SRCS 
-  dap_chain_net_srv.c 
-  dap_chain_net_srv_common.c 
-        )
+      dap_chain_net_srv.c
+      dap_chain_net_srv_order.c
+      dap_chain_net_srv_common.c
+   )
 
 set(DAP_CHAIN_NET_SRV_HEADERS
         dap_chain_net_srv.h
+        dap_chain_net_srv_order.h
         dap_chain_net_srv_common.h
     )
 
diff --git a/dap_chain_net_srv.c b/dap_chain_net_srv.c
index 24b23b2..d21020f 100755
--- a/dap_chain_net_srv.c
+++ b/dap_chain_net_srv.c
@@ -47,7 +47,7 @@
 #include "utlist.h"
 #include "dap_list.h"
 #include "dap_chain_net_srv.h"
-
+#include "dap_chain_net_srv_order.h"
 #define LOG_TAG "chain_net_srv"
 
 static size_t m_uid_count;
@@ -72,7 +72,8 @@ int dap_chain_net_srv_init(void)
 {
     m_uid = NULL;
     m_uid_count = 0;
-
+    if( dap_chain_net_srv_order_init() != 0 )
+        return -1;
     return 0;
 }
 
diff --git a/dap_chain_net_srv_common.h b/dap_chain_net_srv_common.h
index 4dd27fd..1260b6b 100755
--- a/dap_chain_net_srv_common.h
+++ b/dap_chain_net_srv_common.h
@@ -42,11 +42,22 @@ typedef union {
 #endif
 } dap_chain_net_srv_uid_t;
 
+typedef union {
+    uint8_t raw[4];
+    uint32_t raw_ui32[1];
+} dap_chain_net_srv_price_unit_uid_t;
+
+typedef union {
+    uint8_t raw[8];
+    uint32_t raw_ui32[2];
+    uint128_t raw_ui128[1];
+} dap_chain_net_srv_proposal_uid_t;
+
 //Classes of services
-enum {
-    SERV_CLASS_ONCE = 1, // one-time service
-    SERV_CLASS_PERMANENT = 2
-};
+typedef enum {
+    SERV_CLASS_ONCE = 1, // one-time service (Token exchange )
+    SERV_CLASS_PERMANENT = 2 // Permanent working service (VPN, CDN, Streaming)
+} dap_chain_net_srv_class_t;
 
 //Types of services
 enum {
diff --git a/dap_chain_net_srv_order.c b/dap_chain_net_srv_order.c
new file mode 100644
index 0000000..e94fcfa
--- /dev/null
+++ b/dap_chain_net_srv_order.c
@@ -0,0 +1,65 @@
+/*
+ * Authors:
+ * Dmitrii Gerasimov <naeper@demlabs.net>
+ * DeM Labs Inc.   https://demlabs.net
+ * Cellframe https://cellframe.net
+ * Copyright  (c) 2017-2019
+ * All rights reserved.
+
+ This file is part of DAP (Deus Applications Prototypes) the open source project
+
+ DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ DAP is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with any DAP based project.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "dap_chain_net_srv_order.h"
+
+#include "dap_chain_global_db.h"
+
+/**
+ * @brief dap_chain_net_srv_order_init
+ * @return
+ */
+int dap_chain_net_srv_order_init(void)
+{
+    return 0;
+}
+
+/**
+ * @brief dap_chain_net_srv_order_deinit
+ */
+void dap_chain_net_srv_order_deinit()
+{
+
+}
+
+
+dap_chain_net_srv_order_t * dap_chain_net_srv_order_find_by_pid(uint128_t a_proposal_id)
+{
+
+}
+
+int dap_chain_net_srv_order_find_all_by_(uint128_t proposal_id, dap_chain_net_srv_order_t *** a_output_orders, size_t * a_output_size)
+{
+
+}
+
+void dap_chain_net_srv_order_destroy( dap_chain_net_srv_order_t * a_order)
+{
+
+}
+
+void dap_chain_net_srv_order_destroy_all( dap_chain_net_srv_order_t *** a_orders, size_t * a_output_size)
+{
+
+}
diff --git a/dap_chain_net_srv_order.h b/dap_chain_net_srv_order.h
new file mode 100644
index 0000000..323974f
--- /dev/null
+++ b/dap_chain_net_srv_order.h
@@ -0,0 +1,55 @@
+/*
+* Authors:
+* Dmitrii Gerasimov <naeper@demlabs.net>
+* DeM Labs Inc.   https://demlabs.net
+* Cellframe https://cellframe.net
+* Copyright  (c) 2017-2019
+* All rights reserved.
+
+This file is part of DAP (Deus Applications Prototypes) the open source project
+
+DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+DAP is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with any DAP based project.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+#include "dap_common.h"
+#include "dap_chain_net_srv_common.h"
+
+typedef struct dap_chain_net_srv_order
+{
+    dap_chain_net_srv_proposal_uid_t proposal_id; // id trade proposal. Must be unique to the network
+    dap_chain_net_srv_uid_t srv_uid; // Service UID
+    dap_chain_net_srv_class_t srv_class:8; //Class of service (once or permanent)
+    uint64_t *prices; //  service price, for SERV_CLASS_ONCE ONCE for the whole service, for SERV_CLASS_PERMANENT  for one unit.
+    size_t prices_size;
+    dap_chain_net_srv_price_unit_uid_t price_units; // Unit of service (seconds, megabytes, etc.) Only for SERV_CLASS_PERMANENT
+    size_t price_units_size;
+
+    dap_chain_node_addr_t node_addr; // Node address that servs the order (if present)
+    dap_chain_hash_fast_t tx_cond_hash; // Hash index of conditioned transaction attached with order
+
+    char comments[128];
+} dap_chain_net_srv_order_t;
+
+// Init/deinit should be call only if private
+int dap_chain_net_srv_order_init(void);
+void dap_chain_net_srv_order_deinit(void);
+
+dap_chain_net_srv_order_t * dap_chain_net_srv_order_find_by_pid(uint128_t a_proposal_id);
+int dap_chain_net_srv_order_find_all_by(dap_chain_net_srv_uid_t a_srv_uid, dap_chain_net_srv_class_t a_srv_class,
+                                        dap_chain_net_srv_price_unit_uid_t a_price_unit, uint64_t a_price_min, uint64_t a_price_max,
+                                        dap_chain_net_srv_order_t *** a_output_orders, size_t * a_output_size);
+void dap_chain_net_srv_order_destroy( dap_chain_net_srv_order_t * a_order);
+void dap_chain_net_srv_order_destroy_all( dap_chain_net_srv_order_t *** a_orders, size_t * a_output_size);
+
-- 
GitLab