added compiledOn info to d&w
This commit is contained in:
parent
5fd07f7ab5
commit
67d2110b6d
@ -1,7 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/pkg/errors"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@ -40,6 +41,8 @@ type opFlags struct {
|
|||||||
Profile string
|
Profile string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var compiledOn string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
loggerLevel := zap.NewAtomicLevel()
|
loggerLevel := zap.NewAtomicLevel()
|
||||||
// Logging levels: ("debug", "info", "warn", "error", "dpanic", "panic", and "fatal").
|
// Logging levels: ("debug", "info", "warn", "error", "dpanic", "panic", and "fatal").
|
||||||
@ -58,9 +61,10 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
zap.L().Info("magneticod v0.7.0-beta1 has been started.")
|
zap.L().Info("magneticod v0.7.0-beta2 has been started.")
|
||||||
zap.L().Info("Copyright (C) 2017 Mert Bora ALPER <bora@boramalper.org>.")
|
zap.L().Info("Copyright (C) 2018 Mert Bora ALPER <bora@boramalper.org>.")
|
||||||
zap.L().Info("Dedicated to Cemile Binay, in whose hands I thrived.")
|
zap.L().Info("Dedicated to Cemile Binay, in whose hands I thrived.")
|
||||||
|
zap.S().Infof("Compiled on %s", compiledOn)
|
||||||
|
|
||||||
switch opFlags.Verbosity {
|
switch opFlags.Verbosity {
|
||||||
case 0:
|
case 0:
|
||||||
@ -91,18 +95,23 @@ func main() {
|
|||||||
zap.L().Panic("NOT IMPLEMENTED")
|
zap.L().Panic("NOT IMPLEMENTED")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialise the random number generator
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
// Handle Ctrl-C gracefully.
|
// Handle Ctrl-C gracefully.
|
||||||
interruptChan := make(chan os.Signal)
|
interruptChan := make(chan os.Signal)
|
||||||
signal.Notify(interruptChan, os.Interrupt)
|
signal.Notify(interruptChan, os.Interrupt)
|
||||||
|
|
||||||
database, err := persistence.MakeDatabase(opFlags.DatabaseURL, logger)
|
database, err := persistence.MakeDatabase(opFlags.DatabaseURL, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Sugar().Fatalf("Could not open the database at `%s`: %s", opFlags.DatabaseURL, err.Error())
|
logger.Sugar().Fatalf("Could not open the database at `%s`", opFlags.DatabaseURL, zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
trawlingManager := dht.NewTrawlingManager(opFlags.TrawlerMlAddrs)
|
trawlingManager := dht.NewTrawlingManager(opFlags.TrawlerMlAddrs)
|
||||||
metadataSink := metadata.NewSink(2 * time.Minute)
|
metadataSink := metadata.NewSink(2 * time.Minute)
|
||||||
|
|
||||||
|
zap.L().Debug("Peer ID", zap.ByteString("peerID", metadataSink.PeerID))
|
||||||
|
|
||||||
// The Event Loop
|
// The Event Loop
|
||||||
for stopped := false; !stopped; {
|
for stopped := false; !stopped; {
|
||||||
select {
|
select {
|
||||||
@ -117,8 +126,8 @@ func main() {
|
|||||||
|
|
||||||
case md := <-metadataSink.Drain():
|
case md := <-metadataSink.Drain():
|
||||||
if err := database.AddNewTorrent(md.InfoHash, md.Name, md.Files); err != nil {
|
if err := database.AddNewTorrent(md.InfoHash, md.Name, md.Files); err != nil {
|
||||||
logger.Sugar().Fatalf("Could not add new torrent %x to the database: %s",
|
logger.Sugar().Fatalf("Could not add new torrent %x to the database",
|
||||||
md.InfoHash, err.Error())
|
md.InfoHash, zap.Error(err))
|
||||||
}
|
}
|
||||||
zap.L().Info("Fetched!", zap.String("name", md.Name), util.HexField("infoHash", md.InfoHash))
|
zap.L().Info("Fetched!", zap.String("name", md.Name), util.HexField("infoHash", md.InfoHash))
|
||||||
|
|
||||||
@ -147,13 +156,16 @@ func parseFlags() (*opFlags, error) {
|
|||||||
"sqlite3://" +
|
"sqlite3://" +
|
||||||
appdirs.UserDataDir("magneticod", "", "", false) +
|
appdirs.UserDataDir("magneticod", "", "", false) +
|
||||||
"/database.sqlite3" +
|
"/database.sqlite3" +
|
||||||
"?_journal_mode=WAL" // https://github.com/mattn/go-sqlite3#connection-string
|
"?_journal_mode=WAL" + // https://github.com/mattn/go-sqlite3#connection-string
|
||||||
|
"&_busy_timeout=3000" + // in milliseconds
|
||||||
|
"&_foreign_keys=true"
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
opF.DatabaseURL = cmdF.DatabaseURL
|
opF.DatabaseURL = cmdF.DatabaseURL
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = checkAddrs(cmdF.TrawlerMlAddrs); err != nil {
|
if err = checkAddrs(cmdF.TrawlerMlAddrs); err != nil {
|
||||||
zap.S().Fatalf("Of argument (list) `trawler-ml-addr` %s", err.Error())
|
zap.S().Fatalf("Of argument (list) `trawler-ml-addr`", zap.Error(err))
|
||||||
} else {
|
} else {
|
||||||
opF.TrawlerMlAddrs = cmdF.TrawlerMlAddrs
|
opF.TrawlerMlAddrs = cmdF.TrawlerMlAddrs
|
||||||
}
|
}
|
||||||
@ -178,7 +190,7 @@ func checkAddrs(addrs []string) error {
|
|||||||
// well.
|
// well.
|
||||||
_, err := net.ResolveUDPAddr("udp", addr)
|
_, err := net.ResolveUDPAddr("udp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("with %d(th) address `%s`: %s", i+1, addr, err.Error())
|
return errors.Wrapf(err, "%d(th) address (%s) error", i+1, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -31,6 +31,8 @@ import (
|
|||||||
|
|
||||||
const N_TORRENTS = 20
|
const N_TORRENTS = 20
|
||||||
|
|
||||||
|
var compiledOn string
|
||||||
|
|
||||||
// Set a Decoder instance as a package global, because it caches
|
// Set a Decoder instance as a package global, because it caches
|
||||||
// meta-data about structs, and an instance can be shared safely.
|
// meta-data about structs, and an instance can be shared safely.
|
||||||
var decoder = schema.NewDecoder()
|
var decoder = schema.NewDecoder()
|
||||||
@ -44,6 +46,7 @@ var opts struct {
|
|||||||
Credentials map[string][]byte // TODO: encapsulate credentials and mutex for safety
|
Credentials map[string][]byte // TODO: encapsulate credentials and mutex for safety
|
||||||
CredentialsRWMutex sync.RWMutex
|
CredentialsRWMutex sync.RWMutex
|
||||||
CredentialsPath string
|
CredentialsPath string
|
||||||
|
Verbosity int
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -58,14 +61,27 @@ func main() {
|
|||||||
zap.ReplaceGlobals(logger)
|
zap.ReplaceGlobals(logger)
|
||||||
|
|
||||||
zap.L().Info("magneticow v0.7.0-beta1 has been started.")
|
zap.L().Info("magneticow v0.7.0-beta1 has been started.")
|
||||||
zap.L().Info("Copyright (C) 2017 Mert Bora ALPER <bora@boramalper.org>.")
|
zap.L().Info("Copyright (C) 2018 Mert Bora ALPER <bora@boramalper.org>.")
|
||||||
zap.L().Info("Dedicated to Cemile Binay, in whose hands I thrived.")
|
zap.L().Info("Dedicated to Cemile Binay, in whose hands I thrived.")
|
||||||
|
zap.S().Infof("Compiled on %s", compiledOn)
|
||||||
|
|
||||||
if err := parseFlags(); err != nil {
|
if err := parseFlags(); err != nil {
|
||||||
zap.L().Error("Error while initializing", zap.Error(err))
|
zap.L().Error("Error while initializing", zap.Error(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch opts.Verbosity {
|
||||||
|
case 0:
|
||||||
|
loggerLevel.SetLevel(zap.WarnLevel)
|
||||||
|
case 1:
|
||||||
|
loggerLevel.SetLevel(zap.InfoLevel)
|
||||||
|
default: // Default: i.e. in case of 2 or more.
|
||||||
|
// TODO: print the caller (function)'s name and line number!
|
||||||
|
loggerLevel.SetLevel(zap.DebugLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
zap.ReplaceGlobals(logger)
|
||||||
|
|
||||||
// Reload credentials when you receive SIGHUP
|
// Reload credentials when you receive SIGHUP
|
||||||
sighupChan := make(chan os.Signal, 1)
|
sighupChan := make(chan os.Signal, 1)
|
||||||
signal.Notify(sighupChan, syscall.SIGHUP)
|
signal.Notify(sighupChan, syscall.SIGHUP)
|
||||||
@ -190,6 +206,8 @@ func parseFlags() error {
|
|||||||
Database string `short:"d" long:"database" description:"URL of the (magneticod) database"`
|
Database string `short:"d" long:"database" description:"URL of the (magneticod) database"`
|
||||||
Cred string `short:"c" long:"credentials" description:"Path to the credentials file"`
|
Cred string `short:"c" long:"credentials" description:"Path to the credentials file"`
|
||||||
NoAuth bool ` long:"no-auth" description:"Disables authorisation"`
|
NoAuth bool ` long:"no-auth" description:"Disables authorisation"`
|
||||||
|
|
||||||
|
Verbose []bool `short:"v" long:"verbose" description:"Increases verbosity."`
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := flags.Parse(&cmdFlags); err != nil {
|
if _, err := flags.Parse(&cmdFlags); err != nil {
|
||||||
@ -221,8 +239,6 @@ func parseFlags() error {
|
|||||||
opts.CredentialsPath = cmdFlags.Cred
|
opts.CredentialsPath = cmdFlags.Cred
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%v credpath %s\n", cmdFlags.NoAuth, opts.CredentialsPath)
|
|
||||||
|
|
||||||
if opts.CredentialsPath != "" {
|
if opts.CredentialsPath != "" {
|
||||||
opts.Credentials = make(map[string][]byte)
|
opts.Credentials = make(map[string][]byte)
|
||||||
if err := loadCred(opts.CredentialsPath); err != nil {
|
if err := loadCred(opts.CredentialsPath); err != nil {
|
||||||
@ -232,6 +248,8 @@ func parseFlags() error {
|
|||||||
opts.Credentials = nil
|
opts.Credentials = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opts.Verbosity = len(cmdFlags.Verbose)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user