Skip to content

Commit

Permalink
Working p2p relay backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Rocky43007 committed Sep 28, 2024
1 parent c1aba8b commit cec8c9e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apps/mobile/src/components/overview/Devices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
16 changes: 12 additions & 4 deletions apps/mobile/src/screens/settings/info/Debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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!
});
}}
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
2 changes: 1 addition & 1 deletion interface/app/$libraryId/overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
21 changes: 6 additions & 15 deletions interface/app/$libraryId/settings/client/account/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']);
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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!
});
}}
Expand Down
1 change: 1 addition & 0 deletions interface/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cec8c9e

Please sign in to comment.