Skip to content
Snippets Groups Projects
Commit 11b270a9 authored by x18zhan2's avatar x18zhan2
Browse files

some cleaning after merged ws2pheads

parent 0034a9b7
Branches
Tags
No related merge requests found
Pipeline #1351 failed
defmodule Server.Conf.Keypair do
use GenServer
def init(_init) do
#TODO: read keypair from .yml file
seckey = "2DLT4zDuuQSsEehijzkwCwdvH4vrsp6joBf4rum9Zb8jDTBKhDfZawSYsGeWy56cPDUGbWf5ybJgADNnVcnJ3sek"
pubkey = "BhQf2fkGAe1EszyZRJqasMr23YLSf1P3mhuYzEoKpgVA"
{:ok, {pubkey, seckey}}
end
def start_link() do
GenServer.start_link(__MODULE__, [],name: {:via, Registry, {WS2P.HeadCache.Registry, :keypair}})
end
def handle_call({:get_pubkey}, _from, state) do
{pubkey, _} = state
{:reply, pubkey, state}
end
def handle_call({:get_seckey}, _from, state) do
{pubkey, _} = state
{:reply, pubkey, state}
end
end
defmodule Server.Conf.WS2PID do
use GenServer
#TODO: generate ws2pid when we synchronize a node, then put ws2p id into db
def init(_init) do
#TODO: read ws2pid from db
ws2pid = UUID.uuid4() |> String.split("-") |> List.first()
{:ok, ws2pid}
end
def start_link() do
GenServer.start_link(__MODULE__, [],name: {:via, Registry, {WS2P.HeadCache.Registry, :ws2pid}})
end
def handle_call({:get_ws2pid}, _from, ws2pid) do
{:reply, ws2pid, ws2pid}
end
end
defmodule WS2P.HeadsCache do
use GenServer
require Logger
def init(_args) do
{:ok, %{}}
end
@spec start_link(any) :: :ignore | {:error, any} | {:ok, pid}
def start_link(_args) do
GenServer.start_link(__MODULE__, [],
name: {:via, Registry, {WS2P.HeadCache.Registry, :headcache}}
)
end
def handle_call(:get_headcache, _from, state) do
{:reply, state, state}
end
def handle_cast({:update_headcache, new_heads_cache}, _old_heads_cache) do
{:noreply, new_heads_cache}
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment