Deduplicate and maybe works

This commit is contained in:
2026-01-05 17:43:37 +01:00
parent 6bf7e29297
commit 894f4f8601
4 changed files with 19 additions and 11 deletions

View File

@@ -106,6 +106,15 @@ gint teleport_peer_get_port (TeleportPeer *self, gint index, GError **error)
void teleport_peer_add_peer (TeleportPeer *self, gchar *name, gchar *ip, gint port)
{
Peer *element;
for (int i = 0; i < self->list->len; i++) {
element = g_array_index(self->list, Peer *, i);
if (g_strcmp0(element->name, name) == 0) {
g_print("Peer '%s' already exists, skipping duplicate.\n", name);
return;
}
}
Peer *new = g_new(Peer, 1);
new->ip = ip;
new->port = port;

View File

@@ -125,7 +125,7 @@ on_file_chooser_response (GtkNativeDialog *dialog,
if (filename)
{
g_print("Chosen file is %s\n", filename);
teleport_server_add_route (g_compute_checksum_for_string (G_CHECKSUM_SHA256, filename, -1), g_strdup(filename), device->ip);
teleport_server_add_route (g_compute_checksum_for_string (G_CHECKSUM_SHA256, filename, -1), g_strdup(filename), device->ip, device->port);
}
}
@@ -159,7 +159,7 @@ send_file_to_device (GFile *file, Peer *device)
{
g_autofree gchar *filename = g_file_get_path (file);
if (g_file_query_exists (file, NULL)) {
teleport_server_add_route (g_compute_checksum_for_string (G_CHECKSUM_SHA256, filename, -1), g_strdup(filename), device->ip);
teleport_server_add_route (g_compute_checksum_for_string (G_CHECKSUM_SHA256, filename, -1), g_strdup(filename), device->ip, device->port);
}
else {
g_print ("File doesn't exist: %s\n", filename);

View File

@@ -26,7 +26,7 @@
#include "beam-me-up-get.h"
#include "beam-me-up-app.h"
static int port;
static int local_port;
static SoupServer *glob_server;
//static const char *tls_cert_file, *tls_key_file;
@@ -91,7 +91,7 @@ handle_incoming_file(const char *hash,
"s",
g_strdup_printf("http://%s:%d/transfer/%s",
origin,
port,
local_port,
hash)),
g_variant_builder_add (builder, "s", filename);
value = g_variant_new ("as", builder);
@@ -191,7 +191,8 @@ do_server_timeout (gpointer user_data)
int
teleport_server_add_route (gchar *name,
gchar *file_to_send,
gchar *destination) {
gchar *destination,
int remote_port) {
GFile *file;
GFileInfo *fileInfo;
gchar *path;
@@ -211,7 +212,7 @@ teleport_server_add_route (gchar *name,
teleport_get_do_client_notify(g_strdup_printf("http://%s:%d/?token=%s&size=%jd&name=%s\n",
destination,
port,
remote_port,
name,
g_file_info_get_size(fileInfo),
g_file_info_get_display_name(fileInfo)));
@@ -231,10 +232,10 @@ teleport_server_run (void) {
//GTlsCertificate *cert;
GError *error = NULL;
port = 3000;
local_port = 3000;
glob_server = soup_server_new (SOUP_SERVER_SERVER_HEADER, "beam-me-up-httpd ",
NULL);
soup_server_listen_all (glob_server, port, 0, &error);
soup_server_listen_all (glob_server, local_port, 0, &error);
soup_server_add_handler (glob_server, NULL,
server_callback, NULL, NULL);

View File

@@ -20,8 +20,6 @@
#define __TELEPORT_SERVER_H
int teleport_server_run (void);
int teleport_server_add_route (gchar *,
gchar *,
gchar *);
int teleport_server_add_route (gchar *, gchar *, gchar *, int);
#endif /* __TELEPORT_SERVER_H */