Rename subscription to peer (#212)

* Rename subscription to peer

* Rename subscribed to downloading

* Rename publishing to uploading

* Rename subcription to peer in frontend
This commit is contained in:
Jonathan Zernik 2020-08-03 04:20:05 -07:00 committed by GitHub
parent 8767573aef
commit 2486a05d60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 473 additions and 473 deletions

View file

@ -30,13 +30,13 @@ import Widget from "../../components/Widget";
import SqueakThreadItem from "../../components/SqueakThreadItem";
import {
CreateSubscriptionRequest,
CreatePeerRequest,
} from "../../proto/squeak_admin_pb"
import {SqueakAdminClient} from "../../proto/squeak_admin_grpc_web_pb"
var client = new SqueakAdminClient('http://' + window.location.hostname + ':8080')
export default function CreateSubscriptionDialog({
export default function CreatePeerDialog({
open,
handleClose,
...props
@ -44,12 +44,12 @@ export default function CreateSubscriptionDialog({
var classes = useStyles();
const history = useHistory();
var [subscriptionName, setsubscriptionName] = useState('');
var [peerName, setpeerName] = useState('');
var [host, setHost] = useState('');
var [port, setPort] = useState('');
const handleChangeSubscriptionName = (event) => {
setsubscriptionName(event.target.value);
const handleChangePeerName = (event) => {
setpeerName(event.target.value);
};
const handleChangeHost = (event) => {
@ -60,23 +60,23 @@ export default function CreateSubscriptionDialog({
setPort(event.target.value);
};
const createSubscription = (subscriptionName, host, port) => {
console.log("called createSubscription");
const createPeer = (peerName, host, port) => {
console.log("called createPeer");
var createSubscriptionRequest = new CreateSubscriptionRequest()
createSubscriptionRequest.setSubscriptionName(subscriptionName);
createSubscriptionRequest.setHost(host);
createSubscriptionRequest.setPort(port);
console.log(createSubscriptionRequest);
var createPeerRequest = new CreatePeerRequest()
createPeerRequest.setPeerName(peerName);
createPeerRequest.setHost(host);
createPeerRequest.setPort(port);
console.log(createPeerRequest);
client.createSubscription(createSubscriptionRequest, {}, (err, response) => {
client.createPeer(createPeerRequest, {}, (err, response) => {
if (err) {
console.log(err.message);
alert('Error creating subscription: ' + err.message);
alert('Error creating peer: ' + err.message);
return;
}
console.log(response);
console.log(response.getSubscriptionId());
console.log(response.getPeerId());
// goToProfilePage(response.getProfileId());
});
};
@ -87,7 +87,7 @@ export default function CreateSubscriptionDialog({
function handleSubmit(event) {
event.preventDefault();
console.log( 'subscriptionName:', subscriptionName);
console.log( 'peerName:', peerName);
console.log( 'host:', host);
console.log( 'port:', port);
if (!host) {
@ -98,18 +98,18 @@ export default function CreateSubscriptionDialog({
alert('Port cannot be empty.');
return;
}
createSubscription(subscriptionName, host, port);
createPeer(peerName, host, port);
handleClose();
}
function CreateSubscriptionNameInput() {
function CreatePeerNameInput() {
return (
<TextField
id="standard-textarea"
label="Subscription Name"
label="Peer Name"
autoFocus
value={subscriptionName}
onChange={handleChangeSubscriptionName}
value={peerName}
onChange={handleChangePeerName}
fullWidth
inputProps={{ maxLength: 64 }}
/>
@ -154,7 +154,7 @@ export default function CreateSubscriptionDialog({
)
}
function CreateSubscriptionButton() {
function CreatePeerButton() {
return (
<Button
type="submit"
@ -162,18 +162,18 @@ export default function CreateSubscriptionDialog({
color="primary"
className={classes.button}
>
Create Subscription
Create Peer
</Button>
)
}
return (
<Dialog open={open} onClose={handleClose} aria-labelledby="form-dialog-title">
<DialogTitle id="form-dialog-title">Create Subscription</DialogTitle>
<DialogTitle id="form-dialog-title">Create Peer</DialogTitle>
<form className={classes.root} onSubmit={handleSubmit} noValidate autoComplete="off">
<DialogContent>
<div>
{CreateSubscriptionNameInput()}
{CreatePeerNameInput()}
</div>
<div>
{CreateHostInput()}
@ -184,7 +184,7 @@ export default function CreateSubscriptionDialog({
</DialogContent>
<DialogActions>
{CancelButton()}
{CreateSubscriptionButton()}
{CreatePeerButton()}
</DialogActions>
</form>
</Dialog>

View file

@ -0,0 +1,6 @@
{
"name": "CreatePeerDialog",
"version": "0.0.0",
"private": true,
"main": "CreatePeerDialog.js"
}

View file

@ -1,6 +0,0 @@
{
"name": "CreateSubscriptionDialog",
"version": "0.0.0",
"private": true,
"main": "CreateSubscriptionDialog.js"
}

View file

@ -26,8 +26,8 @@ import Maps from "../../pages/maps";
import Profiles from "../../pages/profiles";
import Icons from "../../pages/icons";
import Charts from "../../pages/charts";
import Subscriptions from "../../pages/subscriptions";
import Subscription from "../../pages/subscription";
import Peers from "../../pages/peers";
import Peer from "../../pages/peer";
// context
import { useLayoutState } from "../../context/LayoutContext";
@ -57,8 +57,8 @@ function Layout(props) {
<Route path="/app/profile/:id" component={Profile} />
<Route path="/app/profiles" component={Profiles} />
<Route path="/app/lightning" component={Lightning} />
<Route path="/app/subscriptions" component={Subscriptions} />
<Route path="/app/subscription/:id" component={Subscription} />
<Route path="/app/peers" component={Peers} />
<Route path="/app/peer/:id" component={Peer} />
<Route path="/app/notifications" component={Notifications} />
<Route
exact

View file

@ -9,7 +9,7 @@ import {
LibraryBooks as LibraryIcon,
HelpOutline as FAQIcon,
ArrowBack as ArrowBackIcon,
CloudDownload as SubscriptionIcon,
CloudDownload as PeerIcon,
} from "@material-ui/icons";
import { useTheme } from "@material-ui/styles";
import { withRouter } from "react-router-dom";
@ -33,7 +33,7 @@ const structure = [
{ id: 0, label: "Timeline", link: "/app/timeline", icon: <HomeIcon /> },
{ id: 1, label: "Profiles", link: "/app/profiles", icon: <ProfilesIcon /> },
{ id: 2, label: "Lightning", link: "/app/lightning", icon: <LightningIcon /> },
{ id: 3, label: "Subscriptions", link: "/app/subscriptions", icon: <SubscriptionIcon /> },
{ id: 3, label: "Peers", link: "/app/peers", icon: <PeerIcon /> },
];
function Sidebar({ location }) {

View file

@ -0,0 +1,131 @@
import React, { useState, useEffect } from 'react';
import { useParams } from 'react-router-dom';
import {
Grid,
FormLabel,
FormControl,
FormGroup,
FormControlLabel,
FormHelperText,
Switch,
} from "@material-ui/core";
// styles
import useStyles from "./styles";
// components
import PageTitle from "../../components/PageTitle";
import Widget from "../../components/Widget";
import {
GetPeerRequest,
SetPeerDownloadingRequest,
SetPeerUploadingRequest,
} from "../../proto/squeak_admin_pb"
import { SqueakAdminClient } from "../../proto/squeak_admin_grpc_web_pb"
var client = new SqueakAdminClient('http://' + window.location.hostname + ':8080')
export default function PeerPage() {
var classes = useStyles();
const { id } = useParams();
const [peer, setPeer] = useState(null);
const getPeer = (id) => {
console.log("called getPeer with peerId: " + id);
var getPeerRequest = new GetPeerRequest()
getPeerRequest.setPeerId(id);
console.log(getPeerRequest);
client.getPeer(getPeerRequest, {}, (err, response) => {
console.log(response);
setPeer(response.getSqueakPeer())
});
};
const setDownloading = (id, downloading) => {
console.log("called setDownloading with peerId: " + id + ", downloading: " + downloading);
var setPeerDownloadingRequest = new SetPeerDownloadingRequest()
setPeerDownloadingRequest.setPeerId(id);
setPeerDownloadingRequest.setDownloading(downloading);
console.log(setPeerDownloadingRequest);
client.setPeerDownloading(setPeerDownloadingRequest, {}, (err, response) => {
console.log(response);
getPeer(id);
});
};
const setUploading = (id, uploading) => {
console.log("called setUploading with peerId: " + id + ", uploading: " + uploading);
var setPeerUploadingRequest = new SetPeerUploadingRequest()
setPeerUploadingRequest.setPeerId(id);
setPeerUploadingRequest.setUploading(uploading);
console.log(setPeerUploadingRequest);
client.setPeerUploading(setPeerUploadingRequest, {}, (err, response) => {
console.log(response);
getPeer(id);
});
};
useEffect(()=>{
getPeer(id)
},[id]);
const handleSettingsDownloadingChange = (event) => {
console.log("Downloading changed for peer id: " + id);
console.log("Downloading changed to: " + event.target.checked);
setDownloading(id, event.target.checked);
};
const handleSettingsUploadingChange = (event) => {
console.log("Uploading changed for peer id: " + id);
console.log("Uploading changed to: " + event.target.checked);
setUploading(id, event.target.checked);
};
function NoPeerContent() {
return (
<p>
No peer loaded
</p>
)
}
function PeerContent() {
return (
<>
<p>
Peer name: {peer.getPeerName()}
</p>
{PeerSettingsForm()}
</>
)
}
function PeerSettingsForm() {
return (
<FormControl component="fieldset">
<FormLabel component="legend">Peer settings</FormLabel>
<FormGroup>
<FormControlLabel
control={<Switch checked={peer.getDownloading()} onChange={handleSettingsDownloadingChange} />}
label="Downloading"
/>
<FormControlLabel
control={<Switch checked={peer.getUploading()} onChange={handleSettingsUploadingChange} />}
label="Uploading"
/>
</FormGroup>
</FormControl>
)
}
return (
<>
<PageTitle title={'Peer: ' + (peer ? peer.getPeerName() : null)} />
<div>
{peer
? PeerContent()
: NoPeerContent()
}
</div>
</>
);
}

View file

@ -0,0 +1,6 @@
{
"name": "Peer",
"version": "0.0.0",
"main": "Peer.js",
"private": true
}

View file

@ -19,13 +19,13 @@ import {makeStyles} from '@material-ui/core/styles';
import PageTitle from "../../components/PageTitle";
import Widget from "../../components/Widget";
import Table from "../dashboard/components/Table/Table";
import CreateSubscriptionDialog from "../../components/CreateSubscriptionDialog";
import CreatePeerDialog from "../../components/CreatePeerDialog";
// data
import mock from "../dashboard/mock";
import {
GetSubscriptionsRequest,
GetPeersRequest,
} from "../../proto/squeak_admin_pb"
import {SqueakAdminClient} from "../../proto/squeak_admin_grpc_web_pb"
@ -39,10 +39,10 @@ const useStyles = makeStyles((theme) => ({
}
}));
export default function Subscriptions() {
export default function Peers() {
const classes = useStyles();
const [subscriptions, setSubscriptions] = useState([]);
const [createSubscriptionDialogOpen, setCreateSubscriptionDialogOpen] = useState(false);
const [peers, setPeers] = useState([]);
const [createPeerDialogOpen, setCreatePeerDialogOpen] = useState(false);
const history = useHistory();
function a11yProps(index) {
@ -52,38 +52,38 @@ export default function Subscriptions() {
};
}
const getSqueakSubscriptions = () => {
const getSqueakPeers = () => {
console.log("called getSigningProfiles");
var getSubscriptionsRequest = new GetSubscriptionsRequest();
var getPeersRequest = new GetPeersRequest();
client.getSubscriptions(getSubscriptionsRequest, {}, (err, response) => {
client.getPeers(getPeersRequest, {}, (err, response) => {
if (err) {
console.log(err.message);
return;
}
console.log(response);
setSubscriptions(response.getSqueakSubscriptionsList());
setPeers(response.getSqueakPeersList());
});
};
const goToSubscriptionPage = (id) => {
history.push("/app/Subscription/" + id);
const goToPeerPage = (id) => {
history.push("/app/Peer/" + id);
};
const handleClickOpenCreateSubscriptionDialog = () => {
setCreateSubscriptionDialogOpen(true);
const handleClickOpenCreatePeerDialog = () => {
setCreatePeerDialogOpen(true);
};
const handleCloseCreateSubscriptionDialog = () => {
setCreateSubscriptionDialogOpen(false);
const handleCloseCreatePeerDialog = () => {
setCreatePeerDialogOpen(false);
};
useEffect(() => {
getSqueakSubscriptions()
getSqueakPeers()
}, []);
function CreateSubscriptionButton() {
function CreatePeerButton() {
return (
<>
<Grid item xs={12}>
@ -91,8 +91,8 @@ export default function Subscriptions() {
<Button
variant="contained"
onClick={() => {
handleClickOpenCreateSubscriptionDialog();
}}>Create Subscription
handleClickOpenCreatePeerDialog();
}}>Create Peer
</Button>
</div>
</Grid>
@ -100,22 +100,22 @@ export default function Subscriptions() {
)
}
function SubscriptionsInfo() {
function PeersInfo() {
return (
<>
<Grid container spacing={4}>
{CreateSubscriptionButton()}
{CreatePeerButton()}
<Grid item xs={12}>
<MUIDataTable
title="Subscriptions"
data={subscriptions.map(s =>
title="Peers"
data={peers.map(s =>
[
s.getSubscriptionId(),
s.getSubscriptionName(),
s.getPeerId(),
s.getPeerName(),
s.getHost(),
s.getPort(),
s.getSubscribed().toString(),
s.getPublishing().toString(),
s.getDownloading().toString(),
s.getUploading().toString(),
]
)}
columns={[
@ -128,8 +128,8 @@ export default function Subscriptions() {
"Name",
"Host",
"Port",
"Subscribed",
"Publishing",
"Downloading",
"Uploading",
]}
options={{
filter: false,
@ -139,7 +139,7 @@ export default function Subscriptions() {
onRowClick: rowData => {
var id = rowData[0];
console.log("clicked on id" + id);
goToSubscriptionPage(id);
goToPeerPage(id);
},
}}/>
</Grid>
@ -148,21 +148,21 @@ export default function Subscriptions() {
)
}
function CreateSubscriptionDialogContent() {
function CreatePeerDialogContent() {
return (
<>
<CreateSubscriptionDialog
open={createSubscriptionDialogOpen}
handleClose={handleCloseCreateSubscriptionDialog}
></CreateSubscriptionDialog>
<CreatePeerDialog
open={createPeerDialogOpen}
handleClose={handleCloseCreatePeerDialog}
></CreatePeerDialog>
</>
)
}
return (
<>
< PageTitle title = "Subscriptions" />
{SubscriptionsInfo()}
{CreateSubscriptionDialogContent()}
< PageTitle title = "Peers" />
{PeersInfo()}
{CreatePeerDialogContent()}
< />);
}

View file

@ -0,0 +1,6 @@
{
"name": "Peers",
"version": "0.0.0",
"main": "Peers.js",
"private": true
}

View file

@ -1,131 +0,0 @@
import React, { useState, useEffect } from 'react';
import { useParams } from 'react-router-dom';
import {
Grid,
FormLabel,
FormControl,
FormGroup,
FormControlLabel,
FormHelperText,
Switch,
} from "@material-ui/core";
// styles
import useStyles from "./styles";
// components
import PageTitle from "../../components/PageTitle";
import Widget from "../../components/Widget";
import {
GetSubscriptionRequest,
SetSubscriptionSubscribedRequest,
SetSubscriptionPublishingRequest,
} from "../../proto/squeak_admin_pb"
import { SqueakAdminClient } from "../../proto/squeak_admin_grpc_web_pb"
var client = new SqueakAdminClient('http://' + window.location.hostname + ':8080')
export default function SubscriptionPage() {
var classes = useStyles();
const { id } = useParams();
const [subscription, setSubscription] = useState(null);
const getSubscription = (id) => {
console.log("called getSubscription with subscriptionId: " + id);
var getSubscriptionRequest = new GetSubscriptionRequest()
getSubscriptionRequest.setSubscriptionId(id);
console.log(getSubscriptionRequest);
client.getSubscription(getSubscriptionRequest, {}, (err, response) => {
console.log(response);
setSubscription(response.getSqueakSubscription())
});
};
const setSubscribed = (id, subscribed) => {
console.log("called setSubscribed with subscriptionId: " + id + ", subscribed: " + subscribed);
var setSubscriptionSubscribedRequest = new SetSubscriptionSubscribedRequest()
setSubscriptionSubscribedRequest.setSubscriptionId(id);
setSubscriptionSubscribedRequest.setSubscribed(subscribed);
console.log(setSubscriptionSubscribedRequest);
client.setSubscriptionSubscribed(setSubscriptionSubscribedRequest, {}, (err, response) => {
console.log(response);
getSubscription(id);
});
};
const setPublishing = (id, publishing) => {
console.log("called setPublishing with subscriptionId: " + id + ", publishing: " + publishing);
var setSubscriptionPublishingRequest = new SetSubscriptionPublishingRequest()
setSubscriptionPublishingRequest.setSubscriptionId(id);
setSubscriptionPublishingRequest.setPublishing(publishing);
console.log(setSubscriptionPublishingRequest);
client.setSubscriptionPublishing(setSubscriptionPublishingRequest, {}, (err, response) => {
console.log(response);
getSubscription(id);
});
};
useEffect(()=>{
getSubscription(id)
},[id]);
const handleSettingsSubscribedChange = (event) => {
console.log("Subscribed changed for subscription id: " + id);
console.log("Subscribed changed to: " + event.target.checked);
setSubscribed(id, event.target.checked);
};
const handleSettingsPublishingChange = (event) => {
console.log("Publishing changed for subscription id: " + id);
console.log("Publishing changed to: " + event.target.checked);
setPublishing(id, event.target.checked);
};
function NoSubscriptionContent() {
return (
<p>
No subscription loaded
</p>
)
}
function SubscriptionContent() {
return (
<>
<p>
Subscription name: {subscription.getSubscriptionName()}
</p>
{SubscriptionSettingsForm()}
</>
)
}
function SubscriptionSettingsForm() {
return (
<FormControl component="fieldset">
<FormLabel component="legend">Subscription settings</FormLabel>
<FormGroup>
<FormControlLabel
control={<Switch checked={subscription.getSubscribed()} onChange={handleSettingsSubscribedChange} />}
label="Subscribed"
/>
<FormControlLabel
control={<Switch checked={subscription.getPublishing()} onChange={handleSettingsPublishingChange} />}
label="Publishing"
/>
</FormGroup>
</FormControl>
)
}
return (
<>
<PageTitle title={'Subscription: ' + (subscription ? subscription.getSubscriptionName() : null)} />
<div>
{subscription
? SubscriptionContent()
: NoSubscriptionContent()
}
</div>
</>
);
}

View file

@ -1,6 +0,0 @@
{
"name": "Subscription",
"version": "0.0.0",
"main": "Subscription.js",
"private": true
}

View file

@ -1,6 +0,0 @@
{
"name": "Subscriptions",
"version": "0.0.0",
"main": "Subscriptions.js",
"private": true
}

View file

@ -33,12 +33,12 @@ CREATE TABLE IF NOT EXISTS profile (
whitelisted BOOLEAN NOT NULL
);
CREATE TABLE IF NOT EXISTS subscription (
subscription_id SERIAL PRIMARY KEY,
CREATE TABLE IF NOT EXISTS peer (
peer_id SERIAL PRIMARY KEY,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
subscription_name VARCHAR(64),
peer_name VARCHAR(64),
server_host VARCHAR(256) NOT NULL,
server_port INTEGER NOT NULL,
publishing BOOLEAN NOT NULL,
subscribed BOOLEAN NOT NULL
uploading BOOLEAN NOT NULL,
downloading BOOLEAN NOT NULL
);

View file

@ -108,10 +108,10 @@ def saved_squeak_hash(server_stub, admin_stub, signing_profile_id):
yield bytes.fromhex(squeak_hash_str)
@pytest.fixture
def subscription_id(server_stub, admin_stub):
# Create a new subscription
create_subscription_response = admin_stub.CreateSubscription(
squeak_admin_pb2.CreateSubscriptionRequest(host="fake_host", port=1234,)
def peer_id(server_stub, admin_stub):
# Create a new peer
create_peer_response = admin_stub.CreatePeer(
squeak_admin_pb2.CreatePeerRequest(host="fake_host", port=1234,)
)
subscription_id = create_subscription_response.subscription_id
yield subscription_id
peer_id = create_peer_response.peer_id
yield peer_id

View file

@ -443,76 +443,76 @@ def test_delete_squeak(server_stub, admin_stub, saved_squeak_hash):
)
def test_create_subscription(server_stub, admin_stub):
# Add a new subscription
create_subscription_response = admin_stub.CreateSubscription(
squeak_admin_pb2.CreateSubscriptionRequest(host="fake_host", port=1234,)
def test_create_peer(server_stub, admin_stub):
# Add a new peer
create_peer_response = admin_stub.CreatePeer(
squeak_admin_pb2.CreatePeerRequest(host="fake_host", port=1234,)
)
subscription_id = create_subscription_response.subscription_id
peer_id = create_peer_response.peer_id
# Get the new subscription
get_subscription_response = admin_stub.GetSubscription(
squeak_admin_pb2.GetSubscriptionRequest(
subscription_id=subscription_id,
# Get the new peer
get_peer_response = admin_stub.GetPeer(
squeak_admin_pb2.GetPeerRequest(
peer_id=peer_id,
)
)
assert get_subscription_response.squeak_subscription.host == "fake_host"
assert get_subscription_response.squeak_subscription.port == 1234
assert get_peer_response.squeak_peer.host == "fake_host"
assert get_peer_response.squeak_peer.port == 1234
# Get all subscriptions
get_subscriptions_response = admin_stub.GetSubscriptions(
squeak_admin_pb2.GetSubscriptionsRequest()
# Get all peers
get_peers_response = admin_stub.GetPeers(
squeak_admin_pb2.GetPeersRequest()
)
subscription_hosts = [
squeak_subscription.host
for squeak_subscription in get_subscriptions_response.squeak_subscriptions
peer_hosts = [
squeak_peer.host
for squeak_peer in get_peers_response.squeak_peers
]
assert "fake_host" in subscription_hosts
assert "fake_host" in peer_hosts
def test_set_subscription_subscribed(server_stub, admin_stub, subscription_id):
# Get the subscription
get_subscription_response = admin_stub.GetSubscription(
squeak_admin_pb2.GetSubscriptionRequest(
subscription_id=subscription_id,
def test_set_peer_downloading(server_stub, admin_stub, peer_id):
# Get the peer
get_peer_response = admin_stub.GetPeer(
squeak_admin_pb2.GetPeerRequest(
peer_id=peer_id,
)
)
assert get_subscription_response.squeak_subscription.subscribed == False
assert get_peer_response.squeak_peer.downloading == False
# Set the subscription to be subscribed
admin_stub.SetSubscriptionSubscribed(
squeak_admin_pb2.SetSubscriptionSubscribedRequest(
subscription_id=subscription_id, subscribed=True,
# Set the peer to be downloading
admin_stub.SetPeerDownloading(
squeak_admin_pb2.SetPeerDownloadingRequest(
peer_id=peer_id, downloading=True,
)
)
# Get the subscription again
get_subscription_response = admin_stub.GetSubscription(
squeak_admin_pb2.GetSubscriptionRequest(
subscription_id=subscription_id,
# Get the peer again
get_peer_response = admin_stub.GetPeer(
squeak_admin_pb2.GetPeerRequest(
peer_id=peer_id,
)
)
assert get_subscription_response.squeak_subscription.subscribed == True
assert get_peer_response.squeak_peer.downloading == True
def test_set_subscription_publishing(server_stub, admin_stub, subscription_id):
# Get the subscription
get_subscription_response = admin_stub.GetSubscription(
squeak_admin_pb2.GetSubscriptionRequest(
subscription_id=subscription_id,
def test_set_peer_uploading(server_stub, admin_stub, peer_id):
# Get the peer
get_peer_response = admin_stub.GetPeer(
squeak_admin_pb2.GetPeerRequest(
peer_id=peer_id,
)
)
assert get_subscription_response.squeak_subscription.publishing == False
assert get_peer_response.squeak_peer.uploading == False
# Set the subscription to be publishing
admin_stub.SetSubscriptionPublishing(
squeak_admin_pb2.SetSubscriptionPublishingRequest(
subscription_id=subscription_id, publishing=True,
# Set the peer to be uploading
admin_stub.SetPeerUploading(
squeak_admin_pb2.SetPeerUploadingRequest(
peer_id=peer_id, uploading=True,
)
)
# Get the subscription again
get_subscription_response = admin_stub.GetSubscription(
squeak_admin_pb2.GetSubscriptionRequest(
subscription_id=subscription_id,
# Get the peer again
get_peer_response = admin_stub.GetPeer(
squeak_admin_pb2.GetPeerRequest(
peer_id=peer_id,
)
)
assert get_subscription_response.squeak_subscription.publishing == True
assert get_peer_response.squeak_peer.uploading == True

View file

@ -131,7 +131,7 @@ service Lightning {
the client in which any events relevant to the state of peers are sent
over. Events include peers going online and offline.
*/
rpc SubscribePeerEvents (PeerEventSubscription) returns (stream PeerEvent);
rpc SubscribePeerEvents (PeerEventPeer) returns (stream PeerEvent);
/* lncli: `getinfo`
GetInfo returns general information concerning the lightning node including
@ -170,7 +170,7 @@ service Lightning {
sent over. Events include new active channels, inactive channels, and closed
channels.
*/
rpc SubscribeChannelEvents (ChannelEventSubscription)
rpc SubscribeChannelEvents (ChannelEventPeer)
returns (stream ChannelEventUpdate);
/* lncli: `closedchannels`
@ -312,7 +312,7 @@ service Lightning {
of these fields can be set. If no fields are set, then we'll only send out
the latest add/settle events.
*/
rpc SubscribeInvoices (InvoiceSubscription) returns (stream Invoice);
rpc SubscribeInvoices (InvoicePeer) returns (stream Invoice);
/* lncli: `decodepayreq`
DecodePayReq takes an encoded payment request string and attempts to decode
@ -396,7 +396,7 @@ service Lightning {
channels being advertised, updates in the routing policy for a directional
channel edge, and when channels are closed on-chain.
*/
rpc SubscribeChannelGraph (GraphTopologySubscription)
rpc SubscribeChannelGraph (GraphTopologyPeer)
returns (stream GraphTopologyUpdate);
/* lncli: `debuglevel`
@ -482,7 +482,7 @@ service Lightning {
ups, but the updated set of encrypted multi-chan backups with the closed
channel(s) removed.
*/
rpc SubscribeChannelBackups (ChannelBackupSubscription)
rpc SubscribeChannelBackups (ChannelBackupPeer)
returns (stream ChanBackupSnapshot);
/* lncli: `bakemacaroon`
@ -1416,7 +1416,7 @@ message ListPeersResponse {
repeated Peer peers = 1;
}
message PeerEventSubscription {
message PeerEventPeer {
}
message PeerEvent {
@ -2042,7 +2042,7 @@ message PendingChannelsResponse {
repeated WaitingCloseChannel waiting_close_channels = 5;
}
message ChannelEventSubscription {
message ChannelEventPeer {
}
message ChannelEventUpdate {
@ -2515,7 +2515,7 @@ message StopRequest {
message StopResponse {
}
message GraphTopologySubscription {
message GraphTopologyPeer {
}
message GraphTopologyUpdate {
repeated NodeUpdate node_updates = 1;
@ -2845,7 +2845,7 @@ message ListInvoiceResponse {
uint64 first_index_offset = 3;
}
message InvoiceSubscription {
message InvoicePeer {
/*
If specified (non-zero), then we'll first start by sending out
notifications for all added indexes with an add_index greater than this
@ -3311,7 +3311,7 @@ message RestoreChanBackupRequest {
message RestoreBackupResponse {
}
message ChannelBackupSubscription {
message ChannelBackupPeer {
}
message VerifyChanBackupResponse {

View file

@ -82,25 +82,25 @@ service SqueakAdmin {
*/
rpc DeleteSqueak (DeleteSqueakRequest) returns (DeleteSqueakReply) {}
/** sqkadmin: `addsubscription`
/** sqkadmin: `addpeer`
*/
rpc CreateSubscription (CreateSubscriptionRequest) returns (CreateSubscriptionReply) {}
rpc CreatePeer (CreatePeerRequest) returns (CreatePeerReply) {}
/** sqkadmin: `getsubscription`
/** sqkadmin: `getpeer`
*/
rpc GetSubscription (GetSubscriptionRequest) returns (GetSubscriptionReply) {}
rpc GetPeer (GetPeerRequest) returns (GetPeerReply) {}
/** sqkadmin: `getsubscriptions`
/** sqkadmin: `getpeers`
*/
rpc GetSubscriptions (GetSubscriptionsRequest) returns (GetSubscriptionsReply) {}
rpc GetPeers (GetPeersRequest) returns (GetPeersReply) {}
/** sqkadmin: `setsubscriptionsubscribed`
/** sqkadmin: `setpeerdownloading`
*/
rpc SetSubscriptionSubscribed (SetSubscriptionSubscribedRequest) returns (SetSubscriptionSubscribedReply) {}
rpc SetPeerDownloading (SetPeerDownloadingRequest) returns (SetPeerDownloadingReply) {}
/** sqkadmin: `setsubscriptionsubscribed`
/** sqkadmin: `setpeerdownloading`
*/
rpc SetSubscriptionPublishing (SetSubscriptionPublishingRequest) returns (SetSubscriptionPublishingReply) {}
rpc SetPeerUploading (SetPeerUploadingRequest) returns (SetPeerUploadingReply) {}
}
@ -321,9 +321,9 @@ message DeleteSqueakRequest {
message DeleteSqueakReply {
}
message CreateSubscriptionRequest {
/// Name of the subscription
string subscription_name = 1;
message CreatePeerRequest {
/// Name of the peer
string peer_name = 1;
/// Host
string host = 2;
@ -332,35 +332,35 @@ message CreateSubscriptionRequest {
int32 port = 3;
}
message CreateSubscriptionReply {
/// The subscription id
int32 subscription_id = 1;
message CreatePeerReply {
/// The peer id
int32 peer_id = 1;
}
message GetSubscriptionRequest {
/// The subscription id
int32 subscription_id = 1;
message GetPeerRequest {
/// The peer id
int32 peer_id = 1;
}
message GetSubscriptionReply {
/// The subscription
SqueakSubscription squeak_subscription = 1;
message GetPeerReply {
/// The peer
SqueakPeer squeak_peer = 1;
}
message GetSubscriptionsRequest {
message GetPeersRequest {
}
message GetSubscriptionsReply {
/// The subscriptions
repeated SqueakSubscription squeak_subscriptions = 1;
message GetPeersReply {
/// The peers
repeated SqueakPeer squeak_peers = 1;
}
message SqueakSubscription {
/// The subscription id
int32 subscription_id = 1;
message SqueakPeer {
/// The peer id
int32 peer_id = 1;
/// The subscription name
string subscription_name = 2;
/// The peer name
string peer_name = 2;
/// Host
string host = 3;
@ -368,31 +368,31 @@ message SqueakSubscription {
/// Port
int32 port = 4;
/// Publishing
bool publishing = 5;
/// Uploading
bool uploading = 5;
/// Subscribed
bool subscribed = 6;
/// Downloading
bool downloading = 6;
}
message SetSubscriptionSubscribedRequest {
/// The subscription id
int32 subscription_id = 1;
message SetPeerDownloadingRequest {
/// The peer id
int32 peer_id = 1;
/// Subscribed
bool subscribed = 2;
/// Downloading
bool downloading = 2;
}
message SetSubscriptionSubscribedReply {
message SetPeerDownloadingReply {
}
message SetSubscriptionPublishingRequest {
/// The subscription id
int32 subscription_id = 1;
message SetPeerUploadingRequest {
/// The peer id
int32 peer_id = 1;
/// Publishing
bool publishing = 2;
/// Uploading
bool uploading = 2;
}
message SetSubscriptionPublishingReply {
message SetPeerUploadingReply {
}

View file

@ -153,41 +153,41 @@ class SqueakAdminServerHandler(object):
self.squeak_node.delete_squeak(squeak_hash)
logger.info("Deleted squeak entry with hash: {}".format(squeak_hash))
def handle_create_subscription(self, subscription_name, host, port):
def handle_create_peer(self, peer_name, host, port):
logger.info(
"Handle create subscription with name: {}, host: {}, port: {}".format(
subscription_name, host, port,
"Handle create peer with name: {}, host: {}, port: {}".format(
peer_name, host, port,
)
)
subscription_id = self.squeak_node.create_subscription(
subscription_name,
peer_id = self.squeak_node.create_peer(
peer_name,
host,
port,
)
return subscription_id
return peer_id
def handle_get_squeak_subscription(self, subscription_id):
logger.info("Handle get squeak subscription with id: {}".format(subscription_id))
squeak_subscription = self.squeak_node.get_subscription(subscription_id)
return squeak_subscription
def handle_get_squeak_peer(self, peer_id):
logger.info("Handle get squeak peer with id: {}".format(peer_id))
squeak_peer = self.squeak_node.get_peer(peer_id)
return squeak_peer
def handle_get_squeak_subscriptions(self):
logger.info("Handle get squeak subscriptions")
squeak_subscriptions = self.squeak_node.get_subscriptions()
return squeak_subscriptions
def handle_get_squeak_peers(self):
logger.info("Handle get squeak peers")
squeak_peers = self.squeak_node.get_peers()
return squeak_peers
def handle_set_squeak_subscription_subscribed(self, subscription_id, subscribed):
def handle_set_squeak_peer_downloading(self, peer_id, downloading):
logger.info(
"Handle set subscription subscribed with subscription id: {}, subscribed: {}".format(
subscription_id, subscribed,
"Handle set peer downloading with peer id: {}, downloading: {}".format(
peer_id, downloading,
)
)
self.squeak_node.set_subscription_subscribed(subscription_id, subscribed)
self.squeak_node.set_peer_downloading(peer_id, downloading)
def handle_set_squeak_subscription_publishing(self, subscription_id, publishing):
def handle_set_squeak_peer_uploading(self, peer_id, uploading):
logger.info(
"Handle set subscription publishing with subscription id: {}, publishing: {}".format(
subscription_id, publishing,
"Handle set peer uploading with peer id: {}, uploading: {}".format(
peer_id, uploading,
)
)
self.squeak_node.set_subscription_publishing(subscription_id, publishing)
self.squeak_node.set_peer_uploading(peer_id, uploading)

View file

@ -152,54 +152,54 @@ class SqueakAdminServerServicer(squeak_admin_pb2_grpc.SqueakAdminServicer):
self.handler.handle_delete_squeak(squeak_hash)
return squeak_admin_pb2.DeleteSqueakReply()
def CreateSubscription(self, request, context):
subscription_name = request.subscription_name if request.subscription_name else None
def CreatePeer(self, request, context):
peer_name = request.peer_name if request.peer_name else None
host = request.host
port = request.port
subscription_id = self.handler.handle_create_subscription(
subscription_name,
peer_id = self.handler.handle_create_peer(
peer_name,
host,
port,
)
return squeak_admin_pb2.CreateSubscriptionReply(
subscription_id=subscription_id,
return squeak_admin_pb2.CreatePeerReply(
peer_id=peer_id,
)
def GetSubscription(self, request, context):
subscription_id = request.subscription_id
squeak_subscription = self.handler.handle_get_squeak_subscription(subscription_id)
squeak_subscription_msg = self._squeak_subscription_to_message(squeak_subscription)
return squeak_admin_pb2.GetSubscriptionReply(
squeak_subscription=squeak_subscription_msg,
def GetPeer(self, request, context):
peer_id = request.peer_id
squeak_peer = self.handler.handle_get_squeak_peer(peer_id)
squeak_peer_msg = self._squeak_peer_to_message(squeak_peer)
return squeak_admin_pb2.GetPeerReply(
squeak_peer=squeak_peer_msg,
)
def GetSubscriptions(self, request, context):
squeak_subscriptions = self.handler.handle_get_squeak_subscriptions()
squeak_subscription_msgs = [
self._squeak_subscription_to_message(squeak_subscription)
for squeak_subscription in squeak_subscriptions
def GetPeers(self, request, context):
squeak_peers = self.handler.handle_get_squeak_peers()
squeak_peer_msgs = [
self._squeak_peer_to_message(squeak_peer)
for squeak_peer in squeak_peers
]
return squeak_admin_pb2.GetSubscriptionsReply(
squeak_subscriptions=squeak_subscription_msgs,
return squeak_admin_pb2.GetPeersReply(
squeak_peers=squeak_peer_msgs,
)
def SetSubscriptionSubscribed(self, request, context):
subscription_id = request.subscription_id
subscribed = request.subscribed
self.handler.handle_set_squeak_subscription_subscribed(
subscription_id,
subscribed,
def SetPeerDownloading(self, request, context):
peer_id = request.peer_id
downloading = request.downloading
self.handler.handle_set_squeak_peer_downloading(
peer_id,
downloading,
)
return squeak_admin_pb2.SetSubscriptionSubscribedReply()
return squeak_admin_pb2.SetPeerDownloadingReply()
def SetSubscriptionPublishing(self, request, context):
subscription_id = request.subscription_id
publishing = request.publishing
self.handler.handle_set_squeak_subscription_publishing(
subscription_id,
publishing,
def SetPeerUploading(self, request, context):
peer_id = request.peer_id
uploading = request.uploading
self.handler.handle_set_squeak_peer_uploading(
peer_id,
uploading,
)
return squeak_admin_pb2.SetSubscriptionPublishingReply()
return squeak_admin_pb2.SetPeerUploadingReply()
def _squeak_entry_to_message(self, squeak_entry_with_profile):
if squeak_entry_with_profile is None:
@ -242,16 +242,16 @@ class SqueakAdminServerServicer(squeak_admin_pb2_grpc.SqueakAdminServicer):
whitelisted=squeak_profile.whitelisted,
)
def _squeak_subscription_to_message(self, squeak_subscription):
if squeak_subscription is None:
def _squeak_peer_to_message(self, squeak_peer):
if squeak_peer is None:
return None
return squeak_admin_pb2.SqueakSubscription(
subscription_id=squeak_subscription.subscription_id,
subscription_name=squeak_subscription.subscription_name,
host=squeak_subscription.host,
port=squeak_subscription.port,
publishing=squeak_subscription.publishing,
subscribed=squeak_subscription.subscribed,
return squeak_admin_pb2.SqueakPeer(
peer_id=squeak_peer.peer_id,
peer_name=squeak_peer.peer_name,
host=squeak_peer.host,
port=squeak_peer.port,
uploading=squeak_peer.uploading,
downloading=squeak_peer.downloading,
)
def serve(self):

View file

@ -12,10 +12,10 @@ from squeakserver.node.squeak_maker import SqueakMaker
from squeakserver.node.squeak_rate_limiter import SqueakRateLimiter
from squeakserver.node.squeak_whitelist import SqueakWhitelist
from squeakserver.node.squeak_store import SqueakStore
from squeakserver.node.squeak_subscription_downloader import SqueakSubscriptionDownloader
from squeakserver.node.squeak_peer_downloader import SqueakPeerDownloader
from squeakserver.server.buy_offer import BuyOffer
from squeakserver.server.squeak_profile import SqueakProfile
from squeakserver.server.squeak_subscription import SqueakSubscription
from squeakserver.server.squeak_peer import SqueakPeer
from squeakserver.server.util import generate_offer_preimage
@ -54,7 +54,7 @@ class SqueakNode:
self.squeak_rate_limiter,
self.squeak_whitelist,
)
self.squeak_subscription_downloader = SqueakSubscriptionDownloader(
self.squeak_peer_downloader = SqueakPeerDownloader(
postgres_db,
self.squeak_store,
self.blockchain_client,
@ -63,7 +63,7 @@ class SqueakNode:
def start_running(self):
# self.squeak_block_periodic_worker.start_running()
self.squeak_block_queue_worker.start_running()
self.squeak_subscription_downloader.start_running()
self.squeak_peer_downloader.start_running()
def save_uploaded_squeak(self, squeak):
return self.squeak_store.save_uploaded_squeak(squeak)
@ -201,25 +201,25 @@ class SqueakNode:
def delete_squeak(self, squeak_hash):
return self.squeak_store.delete_squeak(squeak_hash)
def create_subscription(self, subscription_name, host, port):
squeak_subscription = SqueakSubscription(
subscription_id=None,
subscription_name=subscription_name,
def create_peer(self, peer_name, host, port):
squeak_peer = SqueakPeer(
peer_id=None,
peer_name=peer_name,
host=host,
port=port,
publishing=False,
subscribed=False,
uploading=False,
downloading=False,
)
return self.postgres_db.insert_subscription(squeak_subscription)
return self.postgres_db.insert_peer(squeak_peer)
def get_subscription(self, subscription_id):
return self.postgres_db.get_subscription(subscription_id)
def get_peer(self, peer_id):
return self.postgres_db.get_peer(peer_id)
def get_subscriptions(self):
return self.postgres_db.get_subscriptions()
def get_peers(self):
return self.postgres_db.get_peers()
def set_subscription_subscribed(self, subscription_id, subscribed):
self.postgres_db.set_subscription_subscribed(subscription_id, subscribed)
def set_peer_downloading(self, peer_id, downloading):
self.postgres_db.set_peer_downloading(peer_id, downloading)
def set_subscription_publishing(self, subscription_id, publishing):
self.postgres_db.set_subscription_publishing(subscription_id, publishing)
def set_peer_uploading(self, peer_id, uploading):
self.postgres_db.set_peer_uploading(peer_id, uploading)

View file

@ -8,7 +8,7 @@ logger = logging.getLogger(__name__)
SUBSCRIBE_UPDATE_INTERVAL_S = 60.0
class SqueakSubscriptionDownloader:
class SqueakPeerDownloader:
def __init__(self,
postgres_db,
squeak_store,
@ -20,9 +20,9 @@ class SqueakSubscriptionDownloader:
self.blockchain_client = blockchain_client
self.update_interval_s = update_interval_s
def sync_subscriptions(self):
logger.info("Syncing subscriptions...")
subscriptions = self._get_subscriptions()
def sync_peers(self):
logger.info("Syncing peers...")
peers = self._get_peers()
try:
block_info = self.blockchain_client.get_best_block_info()
@ -31,13 +31,13 @@ class SqueakSubscriptionDownloader:
logger.error("Failed to sync because unable to get blockchain info.", exc_info=True)
return
for subscription in subscriptions:
if subscription.subscribed:
logger.info("Syncing subscription: {} with current block: {}".format(subscription, block_height))
for peer in peers:
if peer.downloading:
logger.info("Syncing peer: {} with current block: {}".format(peer, block_height))
def start_running(self):
threading.Timer(self.update_interval_s, self.start_running).start()
self.sync_subscriptions()
self.sync_peers()
def _get_subscriptions(self):
return self.postgres_db.get_subscriptions()
def _get_peers(self):
return self.postgres_db.get_peers()

View file

@ -10,7 +10,7 @@ from squeakserver.blockchain.util import parse_block_header
from squeakserver.core.squeak_entry import SqueakEntry
from squeakserver.core.squeak_entry_with_profile import SqueakEntryWithProfile
from squeakserver.server.squeak_profile import SqueakProfile
from squeakserver.server.squeak_subscription import SqueakSubscription
from squeakserver.server.squeak_peer import SqueakPeer
from squeakserver.server.util import get_hash
logger = logging.getLogger(__name__)
@ -370,69 +370,69 @@ class PostgresDb:
with self.get_cursor() as curs:
curs.execute(sql, (squeak_hash_str,))
def insert_subscription(self, squeak_subscription):
""" Insert a new squeak subscription. """
def insert_peer(self, squeak_peer):
""" Insert a new squeak peer. """
sql = """
INSERT INTO subscription(subscription_name, server_host, server_port, publishing, subscribed)
INSERT INTO peer(peer_name, server_host, server_port, uploading, downloading)
VALUES(%s, %s, %s, %s, %s)
RETURNING subscription_id;
RETURNING peer_id;
"""
with self.get_cursor() as curs:
# execute the INSERT statement
curs.execute(
sql,
(
squeak_subscription.subscription_name,
squeak_subscription.host,
squeak_subscription.port,
squeak_subscription.publishing,
squeak_subscription.subscribed,
squeak_peer.peer_name,
squeak_peer.host,
squeak_peer.port,
squeak_peer.uploading,
squeak_peer.downloading,
),
)
# get the new subscription id back
# get the new peer id back
row = curs.fetchone()
return row["subscription_id"]
return row["peer_id"]
def get_subscription(self, subscription_id):
""" Get a subscription. """
def get_peer(self, peer_id):
""" Get a peer. """
sql = """
SELECT * FROM subscription WHERE subscription_id=%s"""
SELECT * FROM peer WHERE peer_id=%s"""
with self.get_cursor() as curs:
curs.execute(sql, (subscription_id,))
curs.execute(sql, (peer_id,))
row = curs.fetchone()
return self._parse_squeak_subscription(row)
return self._parse_squeak_peer(row)
def get_subscriptions(self):
""" Get all subscriptions. """
def get_peers(self):
""" Get all peers. """
sql = """
SELECT * FROM subscription;
SELECT * FROM peer;
"""
with self.get_cursor() as curs:
curs.execute(sql)
rows = curs.fetchall()
subscriptions = [self._parse_squeak_subscription(row) for row in rows]
return subscriptions
peers = [self._parse_squeak_peer(row) for row in rows]
return peers
def set_subscription_subscribed(self, subscription_id, subscribed):
""" Set a subscription is subscribed. """
def set_peer_downloading(self, peer_id, downloading):
""" Set a peer is downloading. """
sql = """
UPDATE subscription
SET subscribed=%s
WHERE subscription_id=%s;
UPDATE peer
SET downloading=%s
WHERE peer_id=%s;
"""
with self.get_cursor() as curs:
curs.execute(sql, (subscribed, subscription_id,))
curs.execute(sql, (downloading, peer_id,))
def set_subscription_publishing(self, subscription_id, publishing):
""" Set a subscription is publishing. """
def set_peer_uploading(self, peer_id, uploading):
""" Set a peer is uploading. """
sql = """
UPDATE subscription
SET publishing=%s
WHERE subscription_id=%s;
UPDATE peer
SET uploading=%s
WHERE peer_id=%s;
"""
with self.get_cursor() as curs:
curs.execute(sql, (publishing, subscription_id,))
curs.execute(sql, (uploading, peer_id,))
def _parse_squeak_entry(self, row):
vch_decryption_key_column = row["vch_decryption_key"]
@ -486,14 +486,14 @@ class PostgresDb:
squeak_entry=squeak_entry, squeak_profile=squeak_profile,
)
def _parse_squeak_subscription(self, row):
def _parse_squeak_peer(self, row):
if row is None:
return None
return SqueakSubscription(
subscription_id=row["subscription_id"],
subscription_name=row["subscription_name"],
return SqueakPeer(
peer_id=row["peer_id"],
peer_name=row["peer_name"],
host=row["server_host"],
port=row["server_port"],
publishing=row["publishing"],
subscribed=row["subscribed"],
uploading=row["uploading"],
downloading=row["downloading"],
)

View file

@ -0,0 +1,5 @@
from collections import namedtuple
SqueakPeer = namedtuple(
"SqueakPeer", "peer_id, peer_name, host, port, uploading, downloading",
)

View file

@ -1,5 +0,0 @@
from collections import namedtuple
SqueakSubscription = namedtuple(
"SqueakSubscription", "subscription_id, subscription_name, host, port, publishing, subscribed",
)