Skip to content
Snippets Groups Projects
Commit 0034a9b7 authored by x18zhan2's avatar x18zhan2
Browse files

did some cleaning after merge

parent 504cc717
Branches
Tags
No related merge requests found
Pipeline #1350 failed
defmodule Constants do
def medianTime, do: 10
def msValidity, do: 10
def msPeriod, do: 10
def sigValidity, do: 10
def sigPeriod, do: 10
def sigReplay, do: 10
@moduledoc """
A module contains all constants
"""
def head_v0_regexp, do: "^WS2P:HEAD:(" <> pubkey_regexp() <> "):(" <> block_uid_regexp() <> ")$"
def head_v1_regexp() do
"^WS2P(?:O[CT][SAM]?)?(?:I[CT])?:HEAD:1:(" <>
pubkey_regexp() <>
"):(" <>
block_uid_regexp() <>
"):(" <>
ws2pid_regexp() <>
"):(" <>
software() <> "):(" <> software_version() <> "):(" <> zero_or_positive_int() <> ")$"
end
def head_v2_regexp() do
"^WS2P(?:O[CT][SAM]?)?(?:I[CT])?:HEAD:2:(" <>
pubkey_regexp() <>
"):(" <>
block_uid_regexp() <>
"):(" <>
ws2pid_regexp() <>
"):(" <>
software() <>
"):(" <>
software_version() <>
"):(" <>
zero_or_positive_int() <>
"):(" <>
zero_or_positive_int() <>
"):(" <> zero_or_positive_int() <> ")(?::" <> timestamp() <> ")?$"
end
def timestamp, do: "[1-9][0-9]{0,18}"
def zero_or_positive_int, do: "0|[1-9][0-9]{0,18}"
def software, do: "[A-Za-z-_]+"
def software_version, do: "[0-9]+[.][0-9]+[.][0-9]+[-\\w]*"
def ws2p_regexp() do
"WS2P (?:[1-9][0-9]* )?([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?"
end
def ws2p_v2_regexp() do
"WS2P ([1-9][0-9]*) ([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?"
end
def ws2ptor_regexp() do
"WS2PTOR (?:[1-9][0-9]* )?([a-f0-9]{8}) ([a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+.onion) ([0-9]+)(?: (.+))?"
end
def ws2ptor_v2_regexp() do
"WS2PTOR ([1-9][0-9]*) ([a-f0-9]{8}) ([a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+.onion) ([0-9]+)(?: (.+))?"
end
def ws_full_address_onion_regex, do: "(?:wss?:\/\/)(?:www\.)?([0-9a-z]{16}\.onion)(:[0-9]+)?"
def uid_regexp, do: "[A-Za-z0-9_-]{2,100}$"
def pubkey_regexp, do: "(?![OIl])[1-9A-Za-z]{42,45}"
def signature_regexp, do: "[A-Za-z0-9+\\/=]{87,88}"
def block_hash_regexp, do: "[0-9a-fA-F]{5,64}"
def transaction_hash_regexp, do: "[0-9a-fA-F]{5,64}"
def hash_regexp, do: "[A-F0-9]{64}"
def block_id_regexp, do: "[0-9]+"
def block_uid_regexp, do: "(" <> block_id_regexp() <> ")-(" <> block_hash_regexp() <> ")"
def conditions_regexp() do
"(&&|\\|\\|| |[()]|(SIG\\(" <>
pubkey_regexp() <>
"\\)|(XHX\\(" <>
hash_regexp() <> "\\))))*"
end
def host_regexp, do: "[a-z0-9-_.]*(?:.[a-zA-Z])?"
def path_regexp, do: "[/\\w \\.-]*/?"
def ws2pid_regexp, do: "[0-9a-f]{8}"
def ws2p_private_prefix_regexp, do: "O[CT][SAM]"
def ws2p_public_prefix_regexp, do: "I[CT]"
def ws2p_head_regexp, do: "HEAD:?(?:[0-9]+)?"
def empty_hash, do: "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"
def endpoint_flags_regexp, do: "[S]"
def ipv4_regexp() do
"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}" <>
"([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
end
def ipv6_regexp() do
"^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:" <>
"[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:" <>
"([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:" <>
"([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:" <>
"([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}: " <>
"([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}" <>
"((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|" <>
"(([0-9A-Fa-f]{1,4}:){0,5}:((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|" <>
"(2[0-4]d)|(d{1,2}))b))|(::([0-9A-Fa-f]{1,4}:){0,5}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}" <>
"(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|" <>
"([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|" <>
"(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$"
end
end
......@@ -15,6 +15,7 @@ defmodule Dunixir.Application do
Plug.Adapters.Cowboy.child_spec(scheme: :http, plug: ServerHttp.Router, options: [port: 8085]),
{Registry, keys: :unique, name: WS2P.Connection.Registry},
{DynamicSupervisor, strategy: :one_for_one, name: WS2P.ConnectionSupervisor},
WS2P.Cluster,
{Task, fn -> WS2P.Endpoint.accept_connections!(ws2p_port, "/") end}
]
......
......@@ -11,6 +11,107 @@ defmodule Constants do
def sigPeriod, do: 10
def sigReplay, do: 10
def nbDigitsUD, do: 4
def head_v0_regexp, do: "^WS2P:HEAD:(" <> pubkey_regexp() <> "):(" <> block_uid_regexp() <> ")$"
def head_v1_regexp() do
"^WS2P(?:O[CT][SAM]?)?(?:I[CT])?:HEAD:1:(" <>
pubkey_regexp() <>
"):(" <>
block_uid_regexp() <>
"):(" <>
ws2pid_regexp() <>
"):(" <>
software() <> "):(" <> software_version() <> "):(" <> zero_or_positive_int() <> ")$"
end
def head_v2_regexp() do
"^WS2P(?:O[CT][SAM]?)?(?:I[CT])?:HEAD:2:(" <>
pubkey_regexp() <>
"):(" <>
block_uid_regexp() <>
"):(" <>
ws2pid_regexp() <>
"):(" <>
software() <>
"):(" <>
software_version() <>
"):(" <>
zero_or_positive_int() <>
"):(" <>
zero_or_positive_int() <>
"):(" <> zero_or_positive_int() <> ")(?::" <> timestamp() <> ")?$"
end
def timestamp, do: "[1-9][0-9]{0,18}"
def zero_or_positive_int, do: "0|[1-9][0-9]{0,18}"
def software, do: "[A-Za-z-_]+"
def software_version, do: "[0-9]+[.][0-9]+[.][0-9]+[-\\w]*"
def ws2p_regexp() do
"WS2P (?:[1-9][0-9]* )?([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?"
end
def ws2p_v2_regexp() do
"WS2P ([1-9][0-9]*) ([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?"
end
def ws2ptor_regexp() do
"WS2PTOR (?:[1-9][0-9]* )?([a-f0-9]{8}) ([a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+.onion) ([0-9]+)(?: (.+))?"
end
def ws2ptor_v2_regexp() do
"WS2PTOR ([1-9][0-9]*) ([a-f0-9]{8}) ([a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+.onion) ([0-9]+)(?: (.+))?"
end
def ws_full_address_onion_regex, do: "(?:wss?:\/\/)(?:www\.)?([0-9a-z]{16}\.onion)(:[0-9]+)?"
def uid_regexp, do: "[A-Za-z0-9_-]{2,100}$"
def pubkey_regexp, do: "(?![OIl])[1-9A-Za-z]{42,45}"
def signature_regexp, do: "[A-Za-z0-9+\\/=]{87,88}"
def block_hash_regexp, do: "[0-9a-fA-F]{5,64}"
def transaction_hash_regexp, do: "[0-9a-fA-F]{5,64}"
def hash_regexp, do: "[A-F0-9]{64}"
def block_id_regexp, do: "[0-9]+"
def block_uid_regexp, do: "(" <> block_id_regexp() <> ")-(" <> block_hash_regexp() <> ")"
def conditions_regexp() do
"(&&|\\|\\|| |[()]|(SIG\\(" <>
pubkey_regexp() <>
"\\)|(XHX\\(" <>
hash_regexp() <> "\\))))*"
end
def host_regexp, do: "[a-z0-9-_.]*(?:.[a-zA-Z])?"
def path_regexp, do: "[/\\w \\.-]*/?"
def ws2pid_regexp, do: "[0-9a-f]{8}"
def ws2p_private_prefix_regexp, do: "O[CT][SAM]"
def ws2p_public_prefix_regexp, do: "I[CT]"
def ws2p_head_regexp, do: "HEAD:?(?:[0-9]+)?"
def empty_hash, do: "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"
def endpoint_flags_regexp, do: "[S]"
def ipv4_regexp() do
"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}" <>
"([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
end
def ipv6_regexp() do
"^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:" <>
"[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:" <>
"([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:" <>
"([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:" <>
"([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}: " <>
"([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}" <>
"((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|" <>
"(([0-9A-Fa-f]{1,4}:){0,5}:((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|" <>
"(2[0-4]d)|(d{1,2}))b))|(::([0-9A-Fa-f]{1,4}:){0,5}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}" <>
"(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|" <>
"([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|" <>
"(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$"
end
end
defmodule Constants.Contract do
......@@ -43,4 +144,5 @@ end
defmodule Constants.PoW do
def cpu, do: 0.6
def prefix, do: 1
end
......@@ -139,9 +139,12 @@ defmodule WS2P.Cluster do
IO.puts("passed regex verification")
if (sig_ok and sigV2_ok) or sig_ok do
IO.puts("signatures are valid")
step = 0
if heads_cache[full_id]["step"] != nil do
step = heads_cache[full_id]["step"]
end
step = if heads_cache[full_id]["step"] != nil, do: heads_cache[full_id]["step"], else: 0
IO.puts("Signatures are valid")
if heads_cache[full_id] == nil or
Integer.parse(heads_cache[full_id]["blockstamp"]) < Integer.parse(blockstamp) or
......@@ -152,7 +155,7 @@ defmodule WS2P.Cluster do
# Check if pubkey exists
# TODO: searched key in connected key
if server_pubkey || is_member_key(member_keys_cache, pubkey) do
if (server_pubkey != nil || is_member_key(member_keys_cache, pubkey)) do
# if current pubkey exists, put it into member keys cache
member_keys_cache = Map.put(member_keys_cache, pubkey, :os.system_time())
......@@ -281,10 +284,8 @@ defmodule WS2P.Cluster do
# check block information, if it's all valid, if block is good, do following
pubkey = block["issuer"]
# seckey = GenServer.call(:keypair, :get_seckey)
seckey = ""
ws2pid = ""
# ws2pid = GenServer.call(:ws2pid, :get_ws2p_id)
blockstamp = block["number"] <> "-" <> block["hash"]
message =
......@@ -313,7 +314,7 @@ defmodule WS2P.Cluster do
# update headcache
[heads_cache, member_keys_cache, blockstamp_cache] = ws2p_cache
heads_cache = Map.put(heads_cache, my_full_id, broadcast_message)
ws2p_cache = Map.put(ws2p_cache, "heads_cache", heads_cache)
ws2p_cache = Map.put(ws2p_cache, :heads_cache, heads_cache)
{:ok, broadcast_message, ws2p_cache}
end
......
......@@ -2,7 +2,6 @@ defmodule WS2P.HeadsCache do
use GenServer
require Logger
# Registry.start_link(keys: :unique, name: WS2P.HeadCache.Registry)
def init(_args) do
{:ok, %{}}
end
......
......@@ -36,13 +36,9 @@ defmodule Dunixir.MixProject do
{:json, "~> 1.4"},
{:ymlr, "~> 1.0"},
{:ex2ms, "~> 1.0"},
<<<<<<< HEAD
{:jason, "~> 1.2"},
{:elixir_uuid, "~> 1.2"}
=======
{:elixir_uuid, "~> 1.2"},
{:socket, "~> 0.3.13"},
>>>>>>> origin/dev
{:socket, "~> 0.3.13"}
]
end
end
......@@ -12,9 +12,7 @@
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
"enacl": {:hex, :enacl, "1.1.1", "f65dc64d9bff2d8a534cb77aef14da5e7a2fa148987d87856f79a4745c9c2627", [:rebar3], [], "hexpm", "60d329ac3976008f774e21aba254671104976d61a792287615bb26816f09ea0f"},
"ex2ms": {:hex, :ex2ms, "1.6.0", "f39bbd9ff1b0f27b3f707bab2d167066dd8965e7df1149b962d94c74615d0e09", [:mix], [], "hexpm", "0d1ab5e08421af5cd69146efb408dbb1ff77f38a2f4df5f086f2512dc8cf65bf"},
<<<<<<< HEAD
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
=======
"json": {:hex, :json, "1.4.1", "8648f04a9439765ad449bc56a3ff7d8b11dd44ff08ffcdefc4329f7c93843dfa", [:mix], [], "hexpm", "9abf218dbe4ea4fcb875e087d5f904ef263d012ee5ed21d46e9dbca63f053d16"},
"mime": {:hex, :mime, "1.5.0", "203ef35ef3389aae6d361918bf3f952fa17a09e8e43b5aa592b93eba05d0fb8d", [:mix], [], "hexpm", "55a94c0f552249fc1a3dd9cd2d3ab9de9d3c89b559c2bd01121f824834f24746"},
"plug": {:hex, :plug, "1.11.0", "f17217525597628298998bc3baed9f8ea1fa3f1160aa9871aee6df47a6e4d38e", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2d9c633f0499f9dc5c2fd069161af4e2e7756890b81adcbb2ceaa074e8308876"},
......@@ -23,7 +21,6 @@
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"},
"postgrex": {:hex, :postgrex, "0.15.7", "724410acd48abac529d0faa6c2a379fb8ae2088e31247687b16cacc0e0883372", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "88310c010ff047cecd73d5ceca1d99205e4b1ab1b9abfdab7e00f5c9d20ef8f9"},
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
>>>>>>> origin/dev
"scrypt_elixir": {:hex, :scrypt_elixir, "0.1.0", "c603bd2fc5816ac41e2dd3397719afde1adb687e4b79ced71959fbb92e6aa24e", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "b9536accc361e6ea6b284eb8b9795642e2660a63ec232d5ea6e83ca632961037"},
"socket": {:hex, :socket, "0.3.13", "98a2ab20ce17f95fb512c5cadddba32b57273e0d2dba2d2e5f976c5969d0c632", [:mix], [], "hexpm", "f82ea9833ef49dde272e6568ab8aac657a636acb4cf44a7de8a935acb8957c2e"},
"telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},
......
......@@ -9,14 +9,6 @@ defmodule CryptoTest do
priv_key =
"5mMALpffsCVYqBC7suqAc1ffKEU2sTYaUY9WpjS3k1oe5qyLESwyEVjMXy9MgTgd7fyTiV3ryRFXLhpii7Y8QfPG"
<<<<<<< HEAD
test "test signature function" do
message = "Gimme 1000gt"
{seckey, pubkey} = Crypto.generate_keypair()
signature = Crypto.digital_signature(message, seckey)
assert Crypto.verify_digital_signature(signature, message, pubkey)
end
=======
pub_key = "8WUg3M26sPbGq8NonKXNKS6S7qJdCxwabFnBqv54aQLi"
{priv_key_test, pub_key_test} = Crypto.generate_keypair_with_seed(password, salt)
assert priv_key_test == priv_key
......@@ -29,5 +21,4 @@ defmodule CryptoTest do
signature = Crypto.digital_signature(message, seckey)
assert signature = Crypto.verify_digital_signature(signature, message, pubkey)
end
>>>>>>> origin/dev
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment