Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FMSG_ID_URL=http://127.0.0.1:8080

# Optional
FMSG_MAX_MSG_SIZE=10240
FMSG_PORT=36900
FMSG_PORT=4930
FMSG_MAX_PAST_TIME_DELTA=604800
FMSG_MAX_FUTURE_TIME_DELTA=300
FMSG_MIN_DOWNLOAD_RATE=5000
Expand All @@ -20,3 +20,4 @@ PGPORT=
PGUSER=
PGPASSWORD=
PGDATABASE=
PGSSLMODE=disable
16 changes: 2 additions & 14 deletions src/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const (

var ErrProtocolViolation = errors.New("protocol violation")

var Port = env.GetIntDefault("FMSG_PORT", 36900)
var Port = env.GetIntDefault("FMSG_PORT", 4930)

// The only reason RemotePort would ever be different from Port is when running two fmsg hosts on the same machine so the same port is unavaliable.
var RemotePort = env.GetIntDefault("FMSG_REMOTE_PORT", 36900)
var RemotePort = env.GetIntDefault("FMSG_REMOTE_PORT", 4930)
var PastTimeDelta float64 = env.GetFloatDefault("FMSG_MAX_PAST_TIME_DELTA", 7*24*60*60)
var FutureTimeDelta float64 = env.GetFloatDefault("FMSG_MAX_FUTURE_TIME_DELTA", 300)
var MinDownloadRate = env.GetFloatDefault("FMSG_MIN_DOWNLOAD_RATE", 5000)
Expand Down Expand Up @@ -120,18 +120,6 @@ func calcNetIODuration(sizeInBytes int, bytesPerSecond float64) time.Duration {
return d
}

// getDbConnString returns a PostgreSQL connection string using environment variables
// with sslmode=disable to support non-SSL connections
func getDbConnString() string {
connStr := "host=" + os.Getenv("PGHOST") +
" port=" + os.Getenv("PGPORT") +
" user=" + os.Getenv("PGUSER") +
" password=" + os.Getenv("PGPASSWORD") +
" dbname=" + os.Getenv("PGDATABASE") +
" sslmode=disable"
return connStr
}

func parseAddress(b []byte) (*FMsgAddress, error) {
// TODO validate length
var addr = &FMsgAddress{}
Expand Down
8 changes: 4 additions & 4 deletions src/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func testDb() error {
db, err := sql.Open("postgres", getDbConnString())
db, err := sql.Open("postgres", "")
if err != nil {
return err
}
Expand All @@ -17,19 +17,19 @@ func testDb() error {
if err != nil {
return err
}
// TODO check at least tables exisit
// TODO check at least tables exist?
return nil
}

func storeMsgDetail(msg *FMsgHeader) error {

db, err := sql.Open("postgres", getDbConnString())
db, err := sql.Open("postgres", "")
if err != nil {
return err
}
defer db.Close()

stmt, err := db.Prepare(`insert into msg (version
stmt, err := db.Prepare(`insert into msg (version
, flags
, time_sent
, time_recv
Expand Down