forked from cwtch.im/cwtch
all server files now go in configDir, cwtch docker entrypoint sets it by default to where it's expected
This commit is contained in:
parent
bcc94c46e7
commit
9be69bda99
|
@ -28,10 +28,9 @@ RUN apk --no-cache add --update \
|
||||||
zlib-dev \
|
zlib-dev \
|
||||||
zstd \
|
zstd \
|
||||||
zstd-dev \
|
zstd-dev \
|
||||||
#&& wget -q https://www.torproject.org/dist/tor-0.3.4.8.tar.gz \
|
&& wget -q https://www.torproject.org/dist/tor-0.3.5.3-alpha.tar.gz \
|
||||||
&& wget -q https://www.torproject.org/dist/tor-0.3.5.2-alpha.tar.gz \
|
&& tar xf tor-0.3.5.3-alpha.tar.gz \
|
||||||
&& tar xf tor-0.3.5.2-alpha.tar.gz \
|
&& cd tor-0.3.5.3-alpha \
|
||||||
&& cd tor-0.3.5.2-alpha \
|
|
||||||
&& ./configure \
|
&& ./configure \
|
||||||
&& make install \
|
&& make install \
|
||||||
&& ls -R /usr/local/
|
&& ls -R /usr/local/
|
||||||
|
|
|
@ -13,7 +13,7 @@ const (
|
||||||
func main() {
|
func main() {
|
||||||
configDir := os.Getenv("CWTCH_CONFIG_DIR")
|
configDir := os.Getenv("CWTCH_CONFIG_DIR")
|
||||||
|
|
||||||
serverConfig := cwtchserver.LoadConfig(configDir + serverConfigFile)
|
serverConfig := cwtchserver.LoadConfig(configDir, serverConfigFile)
|
||||||
|
|
||||||
server := new(cwtchserver.Server)
|
server := new(cwtchserver.Server)
|
||||||
log.Printf("starting cwtch server...")
|
log.Printf("starting cwtch server...")
|
||||||
|
|
|
@ -25,6 +25,10 @@ tor -f /etc/tor/torrc
|
||||||
#Cwtch will crash and burn if 9051 isn't ready
|
#Cwtch will crash and burn if 9051 isn't ready
|
||||||
sleep 15
|
sleep 15
|
||||||
|
|
||||||
|
if [ -z "${CWTCH_CONFIG_DIR}" ]; then
|
||||||
|
CWTCH_CONFIG_DIR=/etc/cwtch/
|
||||||
|
fi
|
||||||
|
|
||||||
#Run cwtch (or whatever the user passed)
|
#Run cwtch (or whatever the user passed)
|
||||||
exec "$@"
|
exec "$@"
|
||||||
#$@
|
#$@
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/struCoder/pidusage"
|
"github.com/struCoder/pidusage"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,11 +25,13 @@ type Monitors struct {
|
||||||
starttime time.Time
|
starttime time.Time
|
||||||
breakChannel chan bool
|
breakChannel chan bool
|
||||||
log bool
|
log bool
|
||||||
|
configDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start initializes a Monitors's monitors
|
// Start initializes a Monitors's monitors
|
||||||
func (mp *Monitors) Start(ra *application.RicochetApplication, log bool) {
|
func (mp *Monitors) Start(ra *application.RicochetApplication, configDir string, log bool) {
|
||||||
mp.log = log
|
mp.log = log
|
||||||
|
mp.configDir = configDir
|
||||||
mp.starttime = time.Now()
|
mp.starttime = time.Now()
|
||||||
mp.breakChannel = make(chan bool)
|
mp.breakChannel = make(chan bool)
|
||||||
mp.MessageCounter = NewCounter()
|
mp.MessageCounter = NewCounter()
|
||||||
|
@ -54,7 +57,7 @@ func (mp *Monitors) run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mp *Monitors) report() {
|
func (mp *Monitors) report() {
|
||||||
f, err := os.Create(reportFile)
|
f, err := os.Create(path.Join(mp.configDir, reportFile))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ERROR: Could not open monitor reporting file: ", err)
|
log.Println("ERROR: Could not open monitor reporting file: ", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Server struct {
|
||||||
func (s *Server) Run(serverConfig Config) {
|
func (s *Server) Run(serverConfig Config) {
|
||||||
s.config = serverConfig
|
s.config = serverConfig
|
||||||
cwtchserver := new(application.RicochetApplication)
|
cwtchserver := new(application.RicochetApplication)
|
||||||
s.metricsPack.Start(cwtchserver, s.config.ServerReporting.LogMetricsToFile)
|
s.metricsPack.Start(cwtchserver, serverConfig.ConfigDir, s.config.ServerReporting.LogMetricsToFile)
|
||||||
|
|
||||||
l, err := application.SetupOnionV3("127.0.0.1:9051", "tcp4", "", s.config.PrivateKey, utils.GetTorV3Hostname(s.config.PublicKey), 9878)
|
l, err := application.SetupOnionV3("127.0.0.1:9051", "tcp4", "", s.config.PrivateKey, utils.GetTorV3Hostname(s.config.PublicKey), 9878)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ func (s *Server) Run(serverConfig Config) {
|
||||||
af := application.ApplicationInstanceFactory{}
|
af := application.ApplicationInstanceFactory{}
|
||||||
af.Init()
|
af.Init()
|
||||||
ms := new(storage.MessageStore)
|
ms := new(storage.MessageStore)
|
||||||
err = ms.Init(".", s.config.MaxBufferLines, s.metricsPack.MessageCounter)
|
err = ms.Init(serverConfig.ConfigDir, s.config.MaxBufferLines, s.metricsPack.MessageCounter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reporting is a struct for storing a the config a server needs to be a peer, and connect to a group to report
|
// Reporting is a struct for storing a the config a server needs to be a peer, and connect to a group to report
|
||||||
|
@ -18,6 +19,7 @@ type Reporting struct {
|
||||||
|
|
||||||
// Config is a struct for storing basic server configuration
|
// Config is a struct for storing basic server configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
ConfigDir string `json:"-"`
|
||||||
MaxBufferLines int `json:"maxBufferLines"`
|
MaxBufferLines int `json:"maxBufferLines"`
|
||||||
PublicKey ed25519.PublicKey `json:"publicKey"`
|
PublicKey ed25519.PublicKey `json:"publicKey"`
|
||||||
PrivateKey ed25519.PrivateKey `json:"privateKey"`
|
PrivateKey ed25519.PrivateKey `json:"privateKey"`
|
||||||
|
@ -30,19 +32,20 @@ func (config *Config) Identity() identity.Identity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save dumps the latest version of the config to a json file given by filename
|
// Save dumps the latest version of the config to a json file given by filename
|
||||||
func (config *Config) Save(filename string) {
|
func (config *Config) Save(dir, filename string) {
|
||||||
log.Println("Saving config to %s", filename)
|
log.Printf("Saving config to %s\n", path.Join(dir, filename))
|
||||||
bytes, _ := json.MarshalIndent(config, "", "\t")
|
bytes, _ := json.MarshalIndent(config, "", "\t")
|
||||||
ioutil.WriteFile(filename, bytes, 0600)
|
ioutil.WriteFile(path.Join(dir, filename), bytes, 0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadConfig loads a Config from a json file specified by filename
|
// LoadConfig loads a Config from a json file specified by filename
|
||||||
func LoadConfig(filename string) Config {
|
func LoadConfig(configDir, filename string) Config {
|
||||||
log.Printf("Loading config from %s\n", filename)
|
log.Printf("Loading config from %s\n", filename)
|
||||||
config := Config{}
|
config := Config{}
|
||||||
|
config.ConfigDir = configDir
|
||||||
config.MaxBufferLines = 100000
|
config.MaxBufferLines = 100000
|
||||||
config.ServerReporting.LogMetricsToFile = false
|
config.ServerReporting.LogMetricsToFile = false
|
||||||
raw, err := ioutil.ReadFile(filename)
|
raw, err := ioutil.ReadFile(path.Join(configDir, filename))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = json.Unmarshal(raw, &config)
|
err = json.Unmarshal(raw, &config)
|
||||||
|
|
||||||
|
@ -56,6 +59,6 @@ func LoadConfig(filename string) Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always save (first time generation, new version with new variables populated)
|
// Always save (first time generation, new version with new variables populated)
|
||||||
config.Save(filename)
|
config.Save(configDir, filename)
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ func (ms *MessageStore) initAndLoadFiles() error {
|
||||||
ms.activeLogFile = nil
|
ms.activeLogFile = nil
|
||||||
for i := fileStorePartitions - 1; i >= 0; i-- {
|
for i := fileStorePartitions - 1; i >= 0; i-- {
|
||||||
ms.filePos = 0
|
ms.filePos = 0
|
||||||
filename := fmt.Sprintf("%s%s.%d", ms.storeDirectory, fileStoreFilename, i)
|
filename := path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, i))
|
||||||
f, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600)
|
f, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error: MessageStore could not open: %v: %v", filename, err)
|
log.Printf("Error: MessageStore could not open: %v: %v", filename, err)
|
||||||
|
@ -96,13 +97,13 @@ func (ms *MessageStore) updateFile(gm *protocol.GroupMessage) {
|
||||||
|
|
||||||
func (ms *MessageStore) rotateFileStore() {
|
func (ms *MessageStore) rotateFileStore() {
|
||||||
ms.activeLogFile.Close()
|
ms.activeLogFile.Close()
|
||||||
os.Remove(fmt.Sprintf("%s%s.%d", ms.storeDirectory, fileStoreFilename, fileStorePartitions-1))
|
os.Remove(path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, fileStorePartitions-1)))
|
||||||
|
|
||||||
for i := fileStorePartitions - 2; i >= 0; i-- {
|
for i := fileStorePartitions - 2; i >= 0; i-- {
|
||||||
os.Rename(fmt.Sprintf("%s%s.%d", ms.storeDirectory, fileStoreFilename, i), fmt.Sprintf("%s%s.%d", ms.storeDirectory, fileStoreFilename, i+1))
|
os.Rename(path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, i)), path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, i+1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.OpenFile(fmt.Sprintf("%s%s.%d", ms.storeDirectory, fileStoreFilename, 0), os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600)
|
f, err := os.OpenFile(path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, 0)), os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("ERROR: Could not open new message store file in: %s", ms.storeDirectory)
|
log.Printf("ERROR: Could not open new message store file in: %s", ms.storeDirectory)
|
||||||
}
|
}
|
||||||
|
@ -112,7 +113,7 @@ func (ms *MessageStore) rotateFileStore() {
|
||||||
|
|
||||||
// Init sets up a MessageStore of size maxBufferLines (# of messages) backed by filename
|
// Init sets up a MessageStore of size maxBufferLines (# of messages) backed by filename
|
||||||
func (ms *MessageStore) Init(appDirectory string, maxBufferLines int, messageCounter metrics.Counter) error {
|
func (ms *MessageStore) Init(appDirectory string, maxBufferLines int, messageCounter metrics.Counter) error {
|
||||||
ms.storeDirectory = appDirectory + "/" + directory + "/"
|
ms.storeDirectory = path.Join(appDirectory, directory)
|
||||||
os.Mkdir(ms.storeDirectory, 0700)
|
os.Mkdir(ms.storeDirectory, 0700)
|
||||||
|
|
||||||
ms.bufferPos = 0
|
ms.bufferPos = 0
|
||||||
|
|
|
@ -88,7 +88,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
||||||
fmt.Println("No server found!")
|
fmt.Println("No server found!")
|
||||||
server = new(cwtchserver.Server)
|
server = new(cwtchserver.Server)
|
||||||
fmt.Println("Starting cwtch server...")
|
fmt.Println("Starting cwtch server...")
|
||||||
config := cwtchserver.LoadConfig("server-test.json")
|
config := cwtchserver.LoadConfig(".", "server-test.json")
|
||||||
identity := config.Identity()
|
identity := config.Identity()
|
||||||
serverAddr = identity.Hostname()
|
serverAddr = identity.Hostname()
|
||||||
go server.Run(config)
|
go server.Run(config)
|
||||||
|
|
Loading…
Reference in New Issue