Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ FileNest/

```bash
# Clone the repository
git clone https://github.com/lakshyajain-0291/FileNest.git
git clone https://github.com/AISocietyIITJ/FileNest.git
cd FileNest

# Set up backend dependencies
Expand Down
3 changes: 3 additions & 0 deletions UDPmsg/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module UDPmsg

go 1.24.4
93 changes: 93 additions & 0 deletions UDPmsg/peer1/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package main

import (
"bufio"
"fmt"
"log"
"net"
"os"
"strings"
"sync"
"time"
)


func listenmsg(listener *net.UDPConn, wg *sync.WaitGroup) {
defer wg.Done()
listen := make([]byte, 2048)
for {
n, remoteaddr, err := listener.ReadFromUDP(listen)
if err != nil {
log.Fatal(err)
}
message := string(listen[:n])
fmt.Printf("Read a message from %v %s \n", remoteaddr, message)
}
}

func sendmsg(peerAddr *net.UDPAddr, conn *net.UDPConn, wg *sync.WaitGroup) {
defer wg.Done()
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Printf("Please enter your message: ")
if !scanner.Scan() {
break
}

message := strings.TrimSpace(scanner.Text())

if message != "" {
_, err := conn.WriteToUDP([]byte(message), peerAddr)
if err != nil {
fmt.Printf("Error sending message: %v\n", err)
} else {
fmt.Printf("Sent: %s\n", message)
}
}

time.Sleep(100 * time.Millisecond)
}
}

func main() {
// Get local address
myAddr := &net.UDPAddr{
Port: 4321,
IP: net.ParseIP("127.0.0.1"),
}

// Create UDP listener
listener, err := net.ListenUDP("udp", myAddr)
if err != nil {
log.Fatalf("Failed to create UDP listener: %v", err)
}

fmt.Printf("Listening on %s\n", myAddr.String())

// Get peer address
var ip, port string
fmt.Print("Enter peer's IP address: ")
fmt.Scan(&ip)
fmt.Print("Enter peer's port: ")
fmt.Scan(&port)

peerAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%s", ip, port))
if err != nil {
log.Fatal(err)
}

fmt.Printf("Peer address: %s\n", peerAddr.String())

// Use WaitGroup to coordinate goroutines
var wg sync.WaitGroup
wg.Add(2)

// Start listening and sending goroutines
go listenmsg(listener, &wg)
go sendmsg(peerAddr, listener, &wg)

// Wait for both goroutines to finish
wg.Wait()
fmt.Println("Program ended")

}
93 changes: 93 additions & 0 deletions UDPmsg/peer2/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package main

import (
"bufio"
"fmt"
"log"
"net"
"os"
"strings"
"sync"
"time"
)


func listenmsg(listener *net.UDPConn, wg *sync.WaitGroup) {
defer wg.Done()
listen := make([]byte, 2048)
for {
n, remoteaddr, err := listener.ReadFromUDP(listen)
if err != nil {
log.Fatal(err)
}
message := string(listen[:n])
fmt.Printf("Read a message from %v %s \n", remoteaddr, message)
}
}

func sendmsg(peerAddr *net.UDPAddr, conn *net.UDPConn, wg *sync.WaitGroup) {
defer wg.Done()
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Printf("Please enter your message: ")
if !scanner.Scan() {
break
}

message := strings.TrimSpace(scanner.Text())

if message != "" {
_, err := conn.WriteToUDP([]byte(message), peerAddr)
if err != nil {
fmt.Printf("Error sending message: %v\n", err)
} else {
fmt.Printf("Sent: %s\n", message)
}
}

time.Sleep(100 * time.Millisecond)
}
}

func main() {
// Get local address
myAddr := &net.UDPAddr{
Port: 1234,
IP: net.ParseIP("127.0.0.1"),
}

// Create UDP listener
listener, err := net.ListenUDP("udp", myAddr)
if err != nil {
log.Fatalf("Failed to create UDP listener: %v", err)
}

fmt.Printf("Listening on %s\n", myAddr.String())

// Get peer address
var ip, port string
fmt.Print("Enter peer's IP address: ")
fmt.Scan(&ip)
fmt.Print("Enter peer's port: ")
fmt.Scan(&port)

peerAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%s", ip, port))
if err != nil {
log.Fatal(err)
}

fmt.Printf("Peer address: %s\n", peerAddr.String())

// Use WaitGroup to coordinate goroutines
var wg sync.WaitGroup
wg.Add(2)

// Start listening and sending goroutines
go listenmsg(listener, &wg)
go sendmsg(peerAddr, listener, &wg)

// Wait for both goroutines to finish
wg.Wait()
fmt.Println("Program ended")

}
79 changes: 79 additions & 0 deletions XS_proto/PostgreSQL/sql.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package PostgreSQL

import (
"context"
"fmt"
"time"

"github.com/jackc/pgx/v5/pgxpool"
)

func ConnectDB(ctx context.Context, username string, pass string, db_name string) (*pgxpool.Pool, error) {
connStr := fmt.Sprintf("postgres://%s:%s@localhost:5432/%s?sslmode=disable&pool_max_conns=10", username, pass, db_name)

config, err := pgxpool.ParseConfig(connStr)
if err != nil {
return nil, fmt.Errorf("failed to parse config: %w", err)
}

pool, err := pgxpool.NewWithConfig(ctx, config)
if err != nil {
return nil, fmt.Errorf("failed to create connection pool: %w", err)
}

// Test the connection
if err := pool.Ping(ctx); err != nil {
pool.Close()
return nil, fmt.Errorf("failed to ping database: %w", err)
}

return pool, nil
}

func CreateTableIfNotExists(ctx context.Context, pool *pgxpool.Pool, table string) error {
// Drop table if it exists to ensure clean schema
dropSQL := fmt.Sprintf(`DROP TABLE IF EXISTS %s`, table)
_, err := pool.Exec(ctx, dropSQL)
if err != nil {
return fmt.Errorf("failed to drop existing table: %w", err)
}

// Create table with correct schema
sql := fmt.Sprintf(`
CREATE TABLE %s (
id SERIAL PRIMARY KEY,
filename VARCHAR(255) NOT NULL,
filepath TEXT NOT NULL,
embedding FLOAT8[] NOT NULL,
d1tv_id INTEGER NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
)`, table)

_, err = pool.Exec(ctx, sql)
if err != nil {
return fmt.Errorf("failed to create table: %w", err)
}

fmt.Printf("[INFO] Table '%s' created successfully\n", table)
return nil
}

func AddData(ctx context.Context, pool *pgxpool.Pool, table string, filename string, filepath string, embedding []float64, d1tv_id int) error {
sql := fmt.Sprintf(`INSERT INTO %s (filename, filepath, embedding, d1tv_id, created_at)
VALUES ($1, $2, $3, $4, $5)`, table)

ct, err := pool.Exec(ctx, sql,
filename,
filepath,
embedding,
d1tv_id,
time.Now(),
)

if err != nil {
return fmt.Errorf("database insert failed: %w", err)
}

fmt.Printf("[DB INSERT SUCCESS] Rows affected: %d\n", ct.RowsAffected())
return nil
}
29 changes: 29 additions & 0 deletions XS_proto/TV/TV.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package TV

import (
"math/rand"
"sync"
"time"
)

var (
once sync.Once
globalRand *rand.Rand
)

func initRand() {
globalRand = rand.New(rand.NewSource(time.Now().UnixNano()))
}

func Generatetaggingvectors() [][]int {
once.Do(initRand)

taggingVectors := make([][]int, 10)
for j := 0; j < 10; j++ {
taggingVectors[j] = make([]int, 128)
for i := 0; i < 128; i++ {
taggingVectors[j][i] = globalRand.Intn(2)
}
}
return taggingVectors
}
1 change: 1 addition & 0 deletions XS_proto/TestFolder/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Good Morning
1 change: 1 addition & 0 deletions XS_proto/TestFolder/b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bonjour
1 change: 1 addition & 0 deletions XS_proto/TestFolder/c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Guten Tag
1 change: 1 addition & 0 deletions XS_proto/TestFolder/d.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hola
1 change: 1 addition & 0 deletions XS_proto/TestFolder/e.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bom Dia
1 change: 1 addition & 0 deletions XS_proto/TestFolder/f.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ran out of languages
14 changes: 14 additions & 0 deletions XS_proto/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module XSproto

go 1.24.4


require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/sync v0.13.0 // indirect
golang.org/x/text v0.24.0 // indirect
github.com/jackc/pgx/v5 v5.7.5
)
28 changes: 28 additions & 0 deletions XS_proto/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs=
github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 12 additions & 0 deletions XS_proto/logs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Worker-1] Processed file: TestFolder\a.txt β†’ D1TV: 1 (similarity: 0.688115)
[Worker-2] Processed file: TestFolder\c.txt β†’ D1TV: 4 (similarity: 0.650465)
[Worker-4] Processed file: TestFolder\d.txt β†’ D1TV: 5 (similarity: 0.620840)
[Worker-3] Processed file: TestFolder\b.txt β†’ D1TV: 7 (similarity: 0.684859)
[Worker-1] Processed file: TestFolder\f.txt β†’ D1TV: 6 (similarity: 0.704229)
[Worker-5] Processed file: TestFolder\e.txt β†’ D1TV: 4 (similarity: 0.650721)
[Worker-5] Processed file: TestFolder\e.txt β†’ D1TV: 0 (similarity: 0.662181)
[Worker-5] Processed file: TestFolder\f.txt β†’ D1TV: 6 (similarity: 0.662959)
[Worker-3] Processed file: TestFolder\c.txt β†’ D1TV: 0 (similarity: 0.661798)
[Worker-2] Processed file: TestFolder\b.txt β†’ D1TV: 1 (similarity: 0.648956)
[Worker-1] Processed file: TestFolder\a.txt β†’ D1TV: 3 (similarity: 0.629464)
[Worker-4] Processed file: TestFolder\d.txt β†’ D1TV: 1 (similarity: 0.655854)
Loading