Working p2p relay backend

This commit is contained in:
Arnab Chakraborty
2024-09-28 04:01:06 -04:00
parent c1aba8b9cf
commit cec8c9ea86
7 changed files with 23 additions and 23 deletions

View File

@@ -53,7 +53,7 @@ const Devices = ({ node, stats }: Props) => {
})();
}, []);
const devices = useBridgeQuery(['cloud.devices.list', { access_token: accessToken.trim() }]);
const devices = useBridgeQuery(['cloud.devices.list']);
// Refetch devices every 10 seconds
useEffect(() => {

View File

@@ -2,8 +2,7 @@ import { useQueryClient } from '@tanstack/react-query';
import React from 'react';
import { Text, View } from 'react-native';
import {
SyncGroupWithLibraryAndDevices,
toggleFeatureFlag,
CloudSyncGroupWithLibraryAndDevices,
useBridgeMutation,
useBridgeQuery,
useDebugState,
@@ -34,11 +33,12 @@ const DebugScreen = ({ navigation }: SettingsStackScreenProps<'Debug'>) => {
}, []);
const cloudBootstrap = useBridgeMutation(['cloud.bootstrap']);
const addLibraryToCloud = useLibraryMutation('cloud.libraries.create');
const requestJoinSyncGroup = useBridgeMutation('cloud.syncGroups.request_join');
const getGroup = useBridgeQuery([
'cloud.syncGroups.get',
{
pub_id: '0192123b-5d01-7341-aa9d-4a08571052ee',
pub_id: '0192376a-19ff-73a0-98ac-c4fa4043d401',
with_library: true,
with_devices: true,
with_used_storage: true
@@ -108,6 +108,13 @@ const DebugScreen = ({ navigation }: SettingsStackScreenProps<'Debug'>) => {
>
<Text style={tw`text-ink`}>Cloud Bootstrap</Text>
</Button>
<Button
onPress={async () => {
addLibraryToCloud.mutate(null);
}}
>
<Text style={tw`text-ink`}>Add Library to Cloud</Text>
</Button>
<Button
onPress={async () => {
createSyncGroup.mutate(null);
@@ -121,7 +128,8 @@ const DebugScreen = ({ navigation }: SettingsStackScreenProps<'Debug'>) => {
console.log('Current Device: ', currentDevice.data);
console.log('Get Group: ', getGroup.data);
requestJoinSyncGroup.mutate({
sync_group: getGroup.data! as unknown as SyncGroupWithLibraryAndDevices,
sync_group:
getGroup.data! as unknown as CloudSyncGroupWithLibraryAndDevices,
asking_device: currentDevice.data!
});
}}

View File

@@ -122,7 +122,7 @@ impl Node {
std::env::var("SD_CLOUD_P2P_RELAY_URL")
// .unwrap_or_else(|_| "https://use1-1.relay.iroh.network/".to_string()),
// .unwrap_or_else(|_| "http://localhost:8081/".to_string()),
.unwrap_or_else(|_| "https://relay.spacedrive.com/".to_string()),
.unwrap_or_else(|_| "https://relay.spacedrive.com:4433/".to_string()),
std::env::var("SD_CLOUD_P2P_DNS_ORIGIN_NAME")
// .unwrap_or_else(|_| "dns.iroh.link/".to_string()),
// .unwrap_or_else(|_| "irohdns.localhost".to_string()),

View File

@@ -15,7 +15,7 @@ export default function DevicesSection() {
return (
<Section name={t('devices')}>
{node && (
<SidebarLink className="group relative w-full" to={`node/${node.id}`} key={node.id}>
<SidebarLink className="group relative w-full" to={`node/${node.id}`} key={node.id as any}>
{node.device_model ? (
<Icon
name={hardwareModelToIcon(node.device_model as HardwareModel)}

View File

@@ -35,7 +35,7 @@ export const Component = () => {
// not sure if we'll need the node state in the future, as it should be returned with the cloud.devices.list query
// const { data: node } = useBridgeQuery(['nodeState']);
const cloudDevicesList = useBridgeQuery(['cloud.devices.list', { access_token: accessToken }]);
const cloudDevicesList = useBridgeQuery(['cloud.devices.list']);
useEffect(() => {
const interval = setInterval(async () => {

View File

@@ -3,8 +3,7 @@ import { t } from 'i18next';
import { Dispatch, SetStateAction, useEffect } from 'react';
import { signOut } from 'supertokens-web-js/recipe/session';
import {
SyncGroup,
SyncGroupWithLibraryAndDevices,
CloudSyncGroupWithLibraryAndDevices,
useBridgeMutation,
useBridgeQuery,
useLibraryMutation
@@ -34,7 +33,7 @@ const Profile = ({
const emailName = user.email?.split('@')[0];
const capitalizedEmailName = (emailName?.charAt(0).toUpperCase() ?? '') + emailName?.slice(1);
const { accessToken, refreshToken } = getTokens();
console.log(accessToken);
// console.log(accessToken);
const cloudBootstrap = useBridgeMutation('cloud.bootstrap');
const cloudDeleteDevice = useBridgeMutation('cloud.devices.delete');
const devices = useBridgeQuery(['cloud.devices.list']);
@@ -46,15 +45,14 @@ const Profile = ({
const getGroup = useBridgeQuery([
'cloud.syncGroups.get',
{
pub_id: '0192123b-5d01-7341-aa9d-4a08571052ee',
pub_id: '019237a1-586c-7651-afd3-525047b02375',
with_library: true,
with_devices: true,
with_used_storage: true
}
]);
console.log(getGroup.data);
const currentDevice = useBridgeQuery(['cloud.devices.get_current_device']);
console.log('Current Device: ', currentDevice.data);
// console.log('Current Device: ', currentDevice.data);
// Refetch every 10 seconds
useEffect(() => {
@@ -120,14 +118,6 @@ const Profile = ({
>
Start Cloud Bootstrap
</Button>
<Button
className="mt-4 w-full"
onClick={async () => {
cloudDeleteDevice.mutate('01920812-9bd2-7781-aee5-e19a01497296');
}}
>
Delete Device
</Button>
<Button
className="mt-4 w-full"
onClick={async () => {
@@ -167,7 +157,8 @@ const Profile = ({
className="mt-4 w-full"
onClick={async () => {
requestJoinSyncGroup.mutate({
sync_group: getGroup.data! as unknown as SyncGroupWithLibraryAndDevices,
sync_group:
getGroup.data! as unknown as CloudSyncGroupWithLibraryAndDevices,
asking_device: currentDevice.data!
});
}}

View File

@@ -89,6 +89,7 @@ export function SpacedriveInterfaceRoot({ children }: PropsWithChildren) {
useBridgeSubscription(['cloud.listenCloudServicesNotifications'], {
onData: (d) => {
console.log('Received cloud service notification', d);
switch (d.kind) {
case 'ReceivedJoinSyncGroupRequest':
// TODO: Show modal to accept or reject