diff --git a/.gitignore b/.gitignore index d8f4d13a..d07d454b 100644 --- a/.gitignore +++ b/.gitignore @@ -93,7 +93,7 @@ _testmain.go ### Oragono ### -/ircd.* +/ircd* /ssl.* /tls.* /oragono diff --git a/irc/config.go b/irc/config.go index 7eb01379..72894408 100644 --- a/irc/config.go +++ b/irc/config.go @@ -49,11 +49,15 @@ type Config struct { Name string } + Datastore struct { + Path string + SQLitePath string `yaml:"sqlite-path"` + } + Server struct { PassConfig Password string Name string - Database string Listen []string Wslisten string `yaml:"ws-listen"` TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"` @@ -131,8 +135,11 @@ func LoadConfig(filename string) (config *Config, err error) { if !IsHostname(config.Server.Name) { return nil, errors.New("Server name must match the format of a hostname") } - if config.Server.Database == "" { - return nil, errors.New("Server database missing") + if config.Datastore.Path == "" { + 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 { return nil, errors.New("Server listening addresses missing") diff --git a/irc/server.go b/irc/server.go index 384d0c76..65e6006b 100644 --- a/irc/server.go +++ b/irc/server.go @@ -22,6 +22,7 @@ import ( "time" "github.com/DanielOaks/girc-go/ircmsg" + "github.com/tidwall/buntdb" ) type Server struct { @@ -30,6 +31,7 @@ type Server struct { commands chan Command ctime time.Time db *sql.DB + store buntdb.DB idle chan *Client motdLines []string name Name @@ -65,7 +67,7 @@ func NewServer(config *Config) *Server { clients: NewClientLookupSet(), commands: make(chan Command), ctime: time.Now(), - db: OpenDB(config.Server.Database), + db: OpenDB(config.Datastore.SQLitePath), idle: make(chan *Client), name: NewName(config.Server.Name), nameString: NewName(config.Server.Name).String(), @@ -78,6 +80,14 @@ func NewServer(config *Config) *Server { 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 != "" { file, err := os.Open(config.Server.MOTD) if err == nil { diff --git a/oragono.go b/oragono.go index 95ea6d26..5ce0f8e2 100644 --- a/oragono.go +++ b/oragono.go @@ -54,11 +54,11 @@ Options: fmt.Print("\n") fmt.Println(encoded) } else if arguments["initdb"].(bool) { - irc.InitDB(config.Server.Database) - log.Println("database initialized: ", config.Server.Database) + irc.InitDB(config.Datastore.SQLitePath) + log.Println("database initialized: ", config.Datastore.SQLitePath) } else if arguments["upgradedb"].(bool) { - irc.UpgradeDB(config.Server.Database) - log.Println("database upgraded: ", config.Server.Database) + irc.UpgradeDB(config.Datastore.SQLitePath) + log.Println("database upgraded: ", config.Datastore.SQLitePath) } else if arguments["mkcerts"].(bool) { log.Println("making self-signed certificates") diff --git a/oragono.yaml b/oragono.yaml index f8502d3a..e8eb5938 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -5,14 +5,22 @@ network: # name of the network 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: # server name name: oragono.test - # database filename (sqlite db) - database: ircd.db - # addresses to listen on listen: - ":6667"