3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

db: Add very initial buntdb datastore

This commit is contained in:
Daniel Oaks 2016-08-19 23:21:52 +10:00
parent 31757a64d7
commit 1746be2bb8
5 changed files with 37 additions and 12 deletions

2
.gitignore vendored
View File

@ -93,7 +93,7 @@ _testmain.go
### Oragono ### ### Oragono ###
/ircd.* /ircd*
/ssl.* /ssl.*
/tls.* /tls.*
/oragono /oragono

View File

@ -49,11 +49,15 @@ type Config struct {
Name string Name string
} }
Datastore struct {
Path string
SQLitePath string `yaml:"sqlite-path"`
}
Server struct { Server struct {
PassConfig PassConfig
Password string Password string
Name string Name string
Database string
Listen []string Listen []string
Wslisten string `yaml:"ws-listen"` Wslisten string `yaml:"ws-listen"`
TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"` TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"`
@ -131,8 +135,11 @@ func LoadConfig(filename string) (config *Config, err error) {
if !IsHostname(config.Server.Name) { if !IsHostname(config.Server.Name) {
return nil, errors.New("Server name must match the format of a hostname") return nil, errors.New("Server name must match the format of a hostname")
} }
if config.Server.Database == "" { if config.Datastore.Path == "" {
return nil, errors.New("Server database missing") return nil, errors.New("Datastore path missing")
}
if config.Datastore.SQLitePath == "" {
return nil, errors.New("SQLite database path missing")
} }
if len(config.Server.Listen) == 0 { if len(config.Server.Listen) == 0 {
return nil, errors.New("Server listening addresses missing") return nil, errors.New("Server listening addresses missing")

View File

@ -22,6 +22,7 @@ import (
"time" "time"
"github.com/DanielOaks/girc-go/ircmsg" "github.com/DanielOaks/girc-go/ircmsg"
"github.com/tidwall/buntdb"
) )
type Server struct { type Server struct {
@ -30,6 +31,7 @@ type Server struct {
commands chan Command commands chan Command
ctime time.Time ctime time.Time
db *sql.DB db *sql.DB
store buntdb.DB
idle chan *Client idle chan *Client
motdLines []string motdLines []string
name Name name Name
@ -65,7 +67,7 @@ func NewServer(config *Config) *Server {
clients: NewClientLookupSet(), clients: NewClientLookupSet(),
commands: make(chan Command), commands: make(chan Command),
ctime: time.Now(), ctime: time.Now(),
db: OpenDB(config.Server.Database), db: OpenDB(config.Datastore.SQLitePath),
idle: make(chan *Client), idle: make(chan *Client),
name: NewName(config.Server.Name), name: NewName(config.Server.Name),
nameString: NewName(config.Server.Name).String(), nameString: NewName(config.Server.Name).String(),
@ -78,6 +80,14 @@ func NewServer(config *Config) *Server {
checkIdent: config.Server.CheckIdent, checkIdent: config.Server.CheckIdent,
} }
// open data store
db, err := buntdb.Open(config.Datastore.Path)
if err != nil {
log.Fatal(fmt.Sprintf("Failed to open datastore: %s", err.Error()))
}
defer db.Close()
server.store = *db
if config.Server.MOTD != "" { if config.Server.MOTD != "" {
file, err := os.Open(config.Server.MOTD) file, err := os.Open(config.Server.MOTD)
if err == nil { if err == nil {

View File

@ -54,11 +54,11 @@ Options:
fmt.Print("\n") fmt.Print("\n")
fmt.Println(encoded) fmt.Println(encoded)
} else if arguments["initdb"].(bool) { } else if arguments["initdb"].(bool) {
irc.InitDB(config.Server.Database) irc.InitDB(config.Datastore.SQLitePath)
log.Println("database initialized: ", config.Server.Database) log.Println("database initialized: ", config.Datastore.SQLitePath)
} else if arguments["upgradedb"].(bool) { } else if arguments["upgradedb"].(bool) {
irc.UpgradeDB(config.Server.Database) irc.UpgradeDB(config.Datastore.SQLitePath)
log.Println("database upgraded: ", config.Server.Database) log.Println("database upgraded: ", config.Datastore.SQLitePath)
} else if arguments["mkcerts"].(bool) { } else if arguments["mkcerts"].(bool) {
log.Println("making self-signed certificates") log.Println("making self-signed certificates")

View File

@ -5,14 +5,22 @@ network:
# name of the network # name of the network
name: OragonoTest name: OragonoTest
# datastore configuration
datastore:
# path to the datastore
# this can also be ":memory:" for an in-memory-only db
path: ircd.db
# path to our sqlite db
# currently used to lookup masks and store persistent chan data
# but planned to be deprecated in a future release
sqlite-path: ircd-sqlite.db
# server configuration # server configuration
server: server:
# server name # server name
name: oragono.test name: oragono.test
# database filename (sqlite db)
database: ircd.db
# addresses to listen on # addresses to listen on
listen: listen:
- ":6667" - ":6667"