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
33 changes: 0 additions & 33 deletions SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,13 @@ Thanks for using LIBR! Here's how to get help when you need it.
## πŸš€ Quick Help

### πŸ› **Found a Bug?**
<<<<<<< HEAD
[Create a Bug Report](https://github.com/libr-forum/libr/issues/new?template=bug_report.md)

### πŸ’‘ **Have an Idea?**
[Share it in Discussions](https://github.com/libr-forum/libr/discussions/categories/ideas-feature-requests)

### ❓ **Need Help?**
[Ask in Q&A Discussions](https://github.com/libr-forum/libr/discussions/categories/q-a)
=======
[Create a Bug Report](https://github.com/libr-forum/libr/issues/new?template=bug_report.md)

### πŸ’‘ **Have an Idea?**
[Share it in Discussions](https://github.com/libr-forum/libr/discussions/categories/ideas-feature-requests)

### ❓ **Need Help?**
[Ask in Q&A Discussions](https://github.com/libr-forum/libr/discussions/categories/q-a)
>>>>>>> 9778abfea970abad1ec6f572173b51b742c8068d

## πŸ“š **Documentation**

Expand Down Expand Up @@ -50,11 +40,7 @@ git checkout -b update-readme
**Stuck with Git?**
- **Beginner Git Guide:** [git-scm.com/book](https://git-scm.com/book)
- **Interactive Git Tutorial:** [learngitbranching.js.org](https://learngitbranching.js.org/)
<<<<<<< HEAD
- **Ask for help:** [Q&A Discussions](https://github.com/libr-forum/libr/discussions/categories/q-a)
=======
- **Ask for help:** [Q&A Discussions](https://github.com/libr-forum/libr/discussions/categories/q-a)
>>>>>>> 9778abfea970abad1ec6f572173b51b742c8068d

### Common Workflow Questions

Expand All @@ -74,27 +60,16 @@ git rebase main

**"My branch has conflicts, help!"**
1. Don't panic! 😊
<<<<<<< HEAD
2. Ask in [Discussions](https://github.com/libr-forum/libr/discussions)
=======
2. Ask in [Discussions](https://github.com/libr-forum/libr/discussions)
>>>>>>> 9778abfea970abad1ec6f572173b51b742c8068d
3. Our maintainers will help you resolve them

## πŸ’¬ **Community Channels**

### GitHub Discussions (Primary)
<<<<<<< HEAD
- **[General Discussion](https://github.com/libr-forum/libr/discussions/categories/general)** - Chat about anything LIBR-related
- **[Q&A](https://github.com/libr-forum/libr/discussions/categories/q-a)** - Get help from the community
- **[Ideas](https://github.com/libr-forum/libr/discussions/categories/ideas-feature-requests)** - Share feature requests and ideas
- **[Show and Tell](https://github.com/libr-forum/libr/discussions/categories/show-and-tell)** - Share what you've built
=======
- **[General Discussion](https://github.com/libr-forum/libr/discussions/categories/general)** - Chat about anything LIBR-related
- **[Q&A](https://github.com/libr-forum/libr/discussions/categories/q-a)** - Get help from the community
- **[Ideas](https://github.com/libr-forum/libr/discussions/categories/ideas-feature-requests)** - Share feature requests and ideas
- **[Show and Tell](https://github.com/libr-forum/libr/discussions/categories/show-and-tell)** - Share what you've built
>>>>>>> 9778abfea970abad1ec6f572173b51b742c8068d

### Email Support
For private matters or security issues: **devlup@iitj.ac.in**
Expand All @@ -104,11 +79,7 @@ For private matters or security issues: **devlup@iitj.ac.in**
If you're new to open source or Git/GitHub:

1. **Start here:** [New Contributor Guide](docs/BEGINNER_GUIDE.md)
<<<<<<< HEAD
2. **Look for:** Issues labeled [`good first issue`](https://github.com/libr-forum/libr/labels/good%20first%20issue)
=======
2. **Look for:** Issues labeled [`good first issue`](https://github.com/libr-forum/libr/labels/good%20first%20issue)
>>>>>>> 9778abfea970abad1ec6f572173b51b742c8068d
3. **Learn Git:** We have [branch naming guidelines](CONTRIBUTING.md#-branch-naming--workflow-guidelines) to help you!
4. **Get help:** Our [maintainers](docs/MAINTAINER_GUIDE.md) are here to help!

Expand All @@ -123,11 +94,7 @@ If you're new to open source or Git/GitHub:
### Setup Issues
- **Project won't build?** Run `./scripts/setup.sh` first
- **Dependencies missing?** Check our [setup guide](docs/BEGINNER_GUIDE.md#first-time-setup)
<<<<<<< HEAD
- **Still stuck?** Create an issue with the [`help wanted`](https://github.com/libr-forum/libr/labels/help%20wanted) label
=======
- **Still stuck?** Create an issue with the [`help wanted`](https://github.com/libr-forum/libr/labels/help%20wanted) label
>>>>>>> 9778abfea970abad1ec6f572173b51b742c8068d

### Development Questions
- **Don't know which file to edit?** Ask in discussions first
Expand Down
3 changes: 2 additions & 1 deletion core/db/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ DB_PATH = data/libr.db
IP = 49.36.179.166
PORT = 33122
BOOTSTRAP =

JS_ServerURL = https://libr-server.onrender.com
JS_API_KEY = qwertyuiop
3 changes: 3 additions & 0 deletions core/db/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (

"database/sql"
"fmt"
"log"
Expand Down Expand Up @@ -100,3 +101,5 @@ func createTables() error {

return nil
}

var DBtype = "normal"
77 changes: 77 additions & 0 deletions core/db/config/dbConfigManager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package config

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/libr-forum/Libr/core/crypto/logger"
"github.com/libr-forum/Libr/core/db/internal/models"
)

func GetDBConfigPath() string {
var path string

switch runtime.GOOS {
case "windows":
appData := os.Getenv("APPDATA")
path = filepath.Join(appData, "libr", "dbconfig", "dbconfig.json")
case "darwin":
home, _ := os.UserHomeDir()
path = filepath.Join(home, "Library", "Application Support", "libr", "dbconfig", "dbconfig.json")
case "linux":
home, _ := os.UserHomeDir()
path = filepath.Join(home, ".config", "libr", "dbconfig", "dbconfig.json")
default:
path = filepath.Join("dbconfig", "dbconfig.json")
}

return path
}


func ReadDBConfigFile() (models.DBConfig, error) {
path := GetDBConfigPath()
fmt.Println(path)
file, err := os.Open(path)
if err != nil {
logger.LogToFile("failed to open dbconfig.json")
return models.DBConfig{}, fmt.Errorf("failed to open dbconfig.json: %w", err)
}
defer file.Close()

// Debug: print raw file contents
fileInfo, _ := file.Stat()
fileSize := fileInfo.Size()
rawBytes := make([]byte, fileSize)
_, err = file.ReadAt(rawBytes, 0)
if err != nil {
fmt.Println("[DEBUG] Error reading raw file bytes:", err)
} else {
fmt.Println("[DEBUG] Raw dbconfig.json contents:")
fmt.Println(string(rawBytes))
}

// Reset file pointer to beginning for decoding
file.Seek(0, 0)

var configObj models.DBConfig
if err := json.NewDecoder(file).Decode(&configObj); err != nil {
logger.LogToFile("[DEBUG]Failed to decode dbconfig.json")
fmt.Println("[DEBUG] JSON decode error:", err)
return models.DBConfig{}, fmt.Errorf("failed to decode dbconfig.json: %w", err)
}

fmt.Println("[DEBUG] Decoded configObj:", configObj)

// Set DBtype based on API_KEY
if configObj.API_KEY == "" {
DBtype = "normal"
} else {
DBtype = "boot"
}

return configObj, nil
}
65 changes: 65 additions & 0 deletions core/db/config/envconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package config

import (
"log"
"os"
"strconv"
"embed"
"github.com/joho/godotenv"
)
//go:embed .env
var _ embed.FS // Embedded .env file (unused, but required for go:embed syntax)



// Config holds all configuration for the application.
type Config struct {
DBPath string
IP string
Port int
Bootstrap string
JSServerURL string
JSAPIKey string
}

// Cfg is a global, public variable that holds the loaded configuration.



// Cfg is a global, public variable that holds the loaded configuration.
var Cfg Config
func init() {
// Load the .env file.
// It's okay if it fails, we can rely on OS environment variables as a fallback.
if err := godotenv.Load(); err != nil {
log.Println("No .env file found, using OS environment variables")
}

// Load configuration into the Cfg struct
Cfg = Config{
DBPath: getEnv("DB_PATH", "data/default.db"), // Provide a default
IP: getEnv("IP", "0.0.0.0"), // Default to listen on all interfaces
Port: getEnvAsInt("PORT", 33122), // Default port
Bootstrap: getEnv("BOOTSTRAP", ""), // No default needed
JSServerURL: getEnv("JS_ServerURL", ""), // No default needed
JSAPIKey: getEnv("JS_API_KEY", ""), // No default needed
}
log.Println("Configuration loaded successfully")
}

// getEnv is a helper function to read an environment variable or return a default value.
func getEnv(key, fallback string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return fallback
}

// getEnvAsInt is a helper to parse an environment variable as an integer.
func getEnvAsInt(key string, fallback int) int {
valueStr := getEnv(key, "")
if value, err := strconv.Atoi(valueStr); err == nil {
return value
}
return fallback
}
11 changes: 11 additions & 0 deletions core/db/internal/keycache/keycache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"

"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libr-forum/Libr/core/crypto/cryptoutils"
)

Expand All @@ -28,3 +29,13 @@ func LoadPubKey() string {
pub, _, _ := cryptoutils.LoadKeys()
return base64.StdEncoding.EncodeToString(pub)
}

func LoadPrivKey() crypto.PrivKey {
_, priv, _ := cryptoutils.LoadKeys() // priv is ed25519.PrivateKey (a []byte)

libp2pPriv, err := crypto.UnmarshalEd25519PrivateKey(priv)
if err != nil {
panic(err)
}
return libp2pPriv
}
10 changes: 10 additions & 0 deletions core/db/internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ type Mod struct {
PublicKey string `json:"public_key"`
}

type Mods struct{
Peerid string `json:"peer_id"`
PublicKey string `json:"public_key"`
}

type ReportMsg struct {
PublicKey string `json:"public_key"`
Msg Msg `json:"msg"`
Expand Down Expand Up @@ -70,4 +75,9 @@ type KBucket struct {
func (kb *KBucket) String() string {
data, _ := json.MarshalIndent(kb, "", " ")
return string(data)
}

type DBConfig struct {
API_KEY string `json:"x_api_key"`
JS_ServerURL string `json:"jsurl"`
}
18 changes: 17 additions & 1 deletion core/db/internal/network/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,24 @@ import (
func BootstrapFromPeers(dbnodes []*models.Node, localNode *models.Node, rt *routing.RoutingTable) {
fmt.Println("🌐 Bootstrapping from peers...")
for _, n := range dbnodes {
fmt.Printf("PeerId: %s, NodeId: %s\n", n.PeerId, base64.StdEncoding.EncodeToString(n.NodeId[:]))
output := ""

if n.PeerId != "" {
output += fmt.Sprintf("PeerId: %s", n.PeerId)
}

if len(n.NodeId) > 0 {
if output != "" {
output += ", "
}
output += fmt.Sprintf("NodeId: %s", base64.StdEncoding.EncodeToString(n.NodeId[:]))
}

if output != "" {
fmt.Println(output)
}
}

var wg sync.WaitGroup
seen := make(map[string]bool)
var mu sync.Mutex // protect access to `seen` map
Expand Down
4 changes: 2 additions & 2 deletions core/db/internal/network/peers/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func RegisterLocalState(n *models.Node, rt *routing.RoutingTable) {
}

func initDHT() {
bootstrapAddrs, _ := utils.GetDbAddr()
bootstrapAddrs, _ := utils.GetDBFromJSServer()

fmt.Print("Bootstrap addresses: ", bootstrapAddrs, "\n")
// fmt.Print("Bootstrap addresses: ", bootstrapAddrs, "\n")

// 3. Init DB and routing
config.InitDB()
Expand Down
Loading