mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-13 12:33:25 +02:00
Implemented get external address rpc method (#1236)
* Implemented get external address rpc method * Display external address on peers page in frontend * Update frontend build
This commit is contained in:
parent
191a11d424
commit
5e561e6ec2
19 changed files with 104 additions and 15 deletions
|
|
@ -25,6 +25,7 @@ import {
|
|||
getPeersRequest,
|
||||
getConnectedPeersRequest,
|
||||
// subscribeConnectedPeersRequest,
|
||||
getExternalAddressRequest,
|
||||
} from '../../squeakclient/requests';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
|
|
@ -42,6 +43,7 @@ export default function Peers() {
|
|||
const [createPeerDialogOpen, setCreatePeerDialogOpen] = useState(false);
|
||||
const [connectPeerDialogOpen, setConnectPeerDialogOpen] = useState(false);
|
||||
const [value, setValue] = useState(0);
|
||||
const [externalAddress, setExternalAddress] = useState(null);
|
||||
|
||||
function a11yProps(index) {
|
||||
return {
|
||||
|
|
@ -58,6 +60,10 @@ export default function Peers() {
|
|||
getConnectedPeersRequest(setConnectedPeers);
|
||||
};
|
||||
|
||||
const getExternalAddress = () => {
|
||||
getExternalAddressRequest(setExternalAddress);
|
||||
};
|
||||
|
||||
// const subscribeConnectedPeers = () => subscribeConnectedPeersRequest(setConnectedPeers);
|
||||
|
||||
const getSqueakPeers = () => {
|
||||
|
|
@ -90,6 +96,9 @@ export default function Peers() {
|
|||
useEffect(() => {
|
||||
getSqueakPeers();
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
getExternalAddress();
|
||||
}, []);
|
||||
|
||||
function TabPanel(props) {
|
||||
const {
|
||||
|
|
@ -154,6 +163,9 @@ export default function Peers() {
|
|||
<Box
|
||||
p={1}
|
||||
>
|
||||
<Typography variant="h5" component="h5">
|
||||
{`External Address: ${externalAddress && externalAddress.getHost()}:${externalAddress && externalAddress.getPort()}`}
|
||||
</Typography>
|
||||
<Typography variant="h5" component="h5">
|
||||
{`Number of connected peers: ${connectedPeers.length}`}
|
||||
</Typography>
|
||||
|
|
|
|||
|
|
@ -123,6 +123,8 @@ import {
|
|||
GetConnectedPeerReply,
|
||||
ConnectPeerReply as ConnectSqueakPeerReply,
|
||||
DisconnectPeerReply as DisconnectSqueakPeerReply,
|
||||
GetExternalAddressRequest,
|
||||
GetExternalAddressReply,
|
||||
} from '../proto/squeak_admin_pb';
|
||||
|
||||
console.log('The value of REACT_APP_DEV_MODE_ENABLED is:', Boolean(process.env.REACT_APP_DEV_MODE_ENABLED));
|
||||
|
|
@ -1098,6 +1100,21 @@ export function disconnectSqueakPeerRequest(host, port, handleResponse) {
|
|||
// });
|
||||
}
|
||||
|
||||
export function getExternalAddressRequest(handleResponse) {
|
||||
const request = new GetExternalAddressRequest();
|
||||
makeRequest(
|
||||
'getexternaladdress',
|
||||
request,
|
||||
GetExternalAddressReply.deserializeBinary,
|
||||
(response) => {
|
||||
handleResponse(response.getPeerAddress());
|
||||
},
|
||||
);
|
||||
// client.getNetwork(request, {}, (err, response) => {
|
||||
// handleResponse(response.getNetwork());
|
||||
// });
|
||||
}
|
||||
|
||||
// export function subscribeConnectedPeersRequest(handleResponse) {
|
||||
// const request = new SubscribeConnectedPeersRequest();
|
||||
// const stream = client.subscribeConnectedPeers(request);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ from tests.util import download_squeaks
|
|||
from tests.util import download_squeaks_for_address
|
||||
from tests.util import get_connected_peer
|
||||
from tests.util import get_connected_peers
|
||||
from tests.util import get_external_address
|
||||
from tests.util import get_hash
|
||||
from tests.util import get_network
|
||||
from tests.util import get_squeak_display
|
||||
|
|
@ -63,6 +64,15 @@ def test_get_network(admin_stub):
|
|||
assert network == "simnet"
|
||||
|
||||
|
||||
def test_get_external_address(admin_stub):
|
||||
# Get the external address
|
||||
external_address = get_external_address(admin_stub)
|
||||
|
||||
print(external_address)
|
||||
assert external_address.host is not None and len(external_address.host) > 0
|
||||
assert external_address.port > 0
|
||||
|
||||
|
||||
def test_reprocess_received_payments(admin_stub):
|
||||
# Reprocess received payments
|
||||
reprocess_received_payments_response = admin_stub.ReprocessReceivedPayments(
|
||||
|
|
|
|||
|
|
@ -287,6 +287,13 @@ def get_network(node_stub):
|
|||
return get_network_response.network
|
||||
|
||||
|
||||
def get_external_address(node_stub):
|
||||
get_external_address_response = node_stub.GetExternalAddress(
|
||||
squeak_admin_pb2.GetExternalAddressRequest()
|
||||
)
|
||||
return get_external_address_response.peer_address
|
||||
|
||||
|
||||
def make_squeak(node_stub, profile_id, squeak_content, reply_to_hash=None):
|
||||
make_squeak_response = node_stub.MakeSqueak(
|
||||
squeak_admin_pb2.MakeSqueakRequest(
|
||||
|
|
|
|||
|
|
@ -316,6 +316,10 @@ service SqueakAdmin {
|
|||
*/
|
||||
rpc SubscribeTimelineSqueakDisplays (SubscribeTimelineSqueakDisplaysRequest) returns (stream GetSqueakDisplayReply) {}
|
||||
|
||||
/** sqkadmin: `getexternaladdress`
|
||||
*/
|
||||
rpc GetExternalAddress (GetExternalAddressRequest) returns (GetExternalAddressReply) {}
|
||||
|
||||
}
|
||||
|
||||
message CreateSigningProfileRequest {
|
||||
|
|
@ -1133,3 +1137,11 @@ message SubscribeSqueakDisplaysRequest {
|
|||
message SubscribeTimelineSqueakDisplaysRequest {
|
||||
}
|
||||
|
||||
message GetExternalAddressRequest {
|
||||
}
|
||||
|
||||
message GetExternalAddressReply {
|
||||
/// Peer address
|
||||
PeerAddress peer_address = 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ from squeaknode.admin.messages import message_to_sent_payment
|
|||
from squeaknode.admin.messages import message_to_squeak_entry
|
||||
from squeaknode.admin.messages import offer_entry_to_message
|
||||
from squeaknode.admin.messages import payment_summary_to_message
|
||||
from squeaknode.admin.messages import peer_address_to_message
|
||||
from squeaknode.admin.messages import received_payments_to_message
|
||||
from squeaknode.admin.messages import sent_offer_to_message
|
||||
from squeaknode.admin.messages import sent_payment_to_message
|
||||
|
|
@ -1026,3 +1027,11 @@ class SqueakAdminServerHandler(object):
|
|||
yield squeak_admin_pb2.GetSqueakDisplayReply(
|
||||
squeak_display_entry=display_message
|
||||
)
|
||||
|
||||
def handle_get_external_address(self, request):
|
||||
logger.info("Handle get external address")
|
||||
external_address = self.squeak_controller.get_external_address()
|
||||
external_address_msg = peer_address_to_message(external_address)
|
||||
return squeak_admin_pb2.GetExternalAddressReply(
|
||||
peer_address=external_address_msg,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -381,3 +381,6 @@ class SqueakAdminServerServicer(squeak_admin_pb2_grpc.SqueakAdminServicer):
|
|||
request,
|
||||
stopped,
|
||||
)
|
||||
|
||||
def GetExternalAddress(self, request, context):
|
||||
return self.handler.handle_get_external_address(request)
|
||||
|
|
|
|||
|
|
@ -648,6 +648,14 @@ def create_app(handler, username, password):
|
|||
handler.handle_disconnect_peer,
|
||||
)
|
||||
|
||||
@app.route("/getexternaladdress", methods=["POST"])
|
||||
@login_required
|
||||
def getexternaladdress():
|
||||
return handle_request(
|
||||
squeak_admin_pb2.GetExternalAddressRequest(),
|
||||
handler.handle_get_external_address,
|
||||
)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
{
|
||||
"files": {
|
||||
"main.js": "/static/js/main.b5dd81a1.chunk.js",
|
||||
"main.js.map": "/static/js/main.b5dd81a1.chunk.js.map",
|
||||
"main.js": "/static/js/main.52d8797a.chunk.js",
|
||||
"main.js.map": "/static/js/main.52d8797a.chunk.js.map",
|
||||
"runtime-main.js": "/static/js/runtime-main.9f0ba400.js",
|
||||
"runtime-main.js.map": "/static/js/runtime-main.9f0ba400.js.map",
|
||||
"static/css/2.ea4ba2f0.chunk.css": "/static/css/2.ea4ba2f0.chunk.css",
|
||||
"static/js/2.4181937e.chunk.js": "/static/js/2.4181937e.chunk.js",
|
||||
"static/js/2.4181937e.chunk.js.map": "/static/js/2.4181937e.chunk.js.map",
|
||||
"index.html": "/index.html",
|
||||
"precache-manifest.8a0c063712e93bdb27b968958cbb7b2b.js": "/precache-manifest.8a0c063712e93bdb27b968958cbb7b2b.js",
|
||||
"precache-manifest.d491255dedcca5e57be0746e49dc4e44.js": "/precache-manifest.d491255dedcca5e57be0746e49dc4e44.js",
|
||||
"service-worker.js": "/service-worker.js",
|
||||
"static/css/2.ea4ba2f0.chunk.css.map": "/static/css/2.ea4ba2f0.chunk.css.map",
|
||||
"static/js/2.4181937e.chunk.js.LICENSE.txt": "/static/js/2.4181937e.chunk.js.LICENSE.txt",
|
||||
|
|
@ -20,6 +20,6 @@
|
|||
"static/js/runtime-main.9f0ba400.js",
|
||||
"static/css/2.ea4ba2f0.chunk.css",
|
||||
"static/js/2.4181937e.chunk.js",
|
||||
"static/js/main.b5dd81a1.chunk.js"
|
||||
"static/js/main.52d8797a.chunk.js"
|
||||
]
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><title>Squeak Node</title><meta name="description" content="Squeak Node is a frontend for accessing a squeak node"><meta name="keywords" content="squeak, bitcoin, lightning"><meta name="author" content="Flatlogic LLC."><link href="/static/css/2.ea4ba2f0.chunk.css" rel="stylesheet"></head><body style="font-family:Roboto,sans-serif"><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,f,l=r[0],a=r[1],i=r[2],c=0,s=[];c<l.length;c++)f=l[c],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,i||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var a=t[l];0!==o[a]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this["webpackJsonpsqueak-node-frontend"]=this["webpackJsonpsqueak-node-frontend"]||[],a=l.push.bind(l);l.push=r,l=l.slice();for(var i=0;i<l.length;i++)r(l[i]);var p=a;t()}([])</script><script src="/static/js/2.4181937e.chunk.js"></script><script src="/static/js/main.b5dd81a1.chunk.js"></script></body></html>
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><title>Squeak Node</title><meta name="description" content="Squeak Node is a frontend for accessing a squeak node"><meta name="keywords" content="squeak, bitcoin, lightning"><meta name="author" content="Flatlogic LLC."><link href="/static/css/2.ea4ba2f0.chunk.css" rel="stylesheet"></head><body style="font-family:Roboto,sans-serif"><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,f,l=r[0],a=r[1],i=r[2],c=0,s=[];c<l.length;c++)f=l[c],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,i||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var a=t[l];0!==o[a]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this["webpackJsonpsqueak-node-frontend"]=this["webpackJsonpsqueak-node-frontend"]||[],a=l.push.bind(l);l.push=r,l=l.slice();for(var i=0;i<l.length;i++)r(l[i]);var p=a;t()}([])</script><script src="/static/js/2.4181937e.chunk.js"></script><script src="/static/js/main.52d8797a.chunk.js"></script></body></html>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
self.__precacheManifest = (self.__precacheManifest || []).concat([
|
||||
{
|
||||
"revision": "47dabe8d9a77cca2c8d5407e18931825",
|
||||
"revision": "a52c18e51d6339e1839acab673a2b868",
|
||||
"url": "/index.html"
|
||||
},
|
||||
{
|
||||
|
|
@ -16,8 +16,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
|
|||
"url": "/static/js/2.4181937e.chunk.js.LICENSE.txt"
|
||||
},
|
||||
{
|
||||
"revision": "519826351c7336fbd239",
|
||||
"url": "/static/js/main.b5dd81a1.chunk.js"
|
||||
"revision": "142803ca6982e88c4aff",
|
||||
"url": "/static/js/main.52d8797a.chunk.js"
|
||||
},
|
||||
{
|
||||
"revision": "cc9816de5a8639d377ea",
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
|
||||
|
||||
importScripts(
|
||||
"/precache-manifest.8a0c063712e93bdb27b968958cbb7b2b.js"
|
||||
"/precache-manifest.d491255dedcca5e57be0746e49dc4e44.js"
|
||||
);
|
||||
|
||||
self.addEventListener('message', (event) => {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -118,8 +118,6 @@ class WebadminConfig(Config):
|
|||
class NodeConfig(Config):
|
||||
network = key(
|
||||
cast=str, required=False, default=DEFAULT_NETWORK)
|
||||
default_peer_rpc_port = key(
|
||||
cast=int, required=False, default=DEFAULT_SERVER_RPC_PORT)
|
||||
price_msat = key(
|
||||
cast=int, required=False, default=DEFAULT_PRICE_MSAT)
|
||||
max_squeaks = key(
|
||||
|
|
@ -146,6 +144,8 @@ class NodeConfig(Config):
|
|||
cast=str, required=False, default="")
|
||||
tor_proxy_port = key(
|
||||
cast=int, required=False, default=0)
|
||||
p2p_hidden_service_address = key(
|
||||
cast=str, required=False, default="")
|
||||
|
||||
|
||||
@section('db')
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ class NetworkManager(object):
|
|||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.local_ip = socket.gethostbyname('localhost')
|
||||
self.local_ip = self.config.node.p2p_hidden_service_address or socket.gethostbyname(
|
||||
'localhost')
|
||||
self.local_port = self.config.server.rpc_port or squeak.params.params.DEFAULT_PORT
|
||||
self.peer_server = None
|
||||
self.peer_client = None
|
||||
|
|
@ -140,6 +141,13 @@ class NetworkManager(object):
|
|||
self.local_port,
|
||||
)
|
||||
|
||||
@property
|
||||
def external_address(self) -> PeerAddress:
|
||||
return PeerAddress(
|
||||
self.local_ip,
|
||||
self.local_port,
|
||||
)
|
||||
|
||||
def subscribe_connected_peers(self, stopped):
|
||||
yield from self.connection_manager.yield_peers_changed(stopped)
|
||||
|
||||
|
|
|
|||
|
|
@ -809,3 +809,6 @@ class SqueakController:
|
|||
if str(item.GetAddress()) in set(followed_addresses):
|
||||
squeak_hash = get_hash(item)
|
||||
yield self.get_squeak_entry(squeak_hash)
|
||||
|
||||
def get_external_address(self) -> PeerAddress:
|
||||
return self.network_manager.external_address
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue