7 Commits

5 changed files with 61 additions and 13 deletions

View File

@@ -1,2 +1,3 @@
945ab4b16d05aa084f71bf5da9a3f687e0ec8bbd libnmdc-r1
02a360e95480b97ddad83add5db48b2766339a99 nmdc-log-service-1.0.0
137c1b65039e03c80379826a6efdfd808f6fbc8f libnmdc-r2

View File

@@ -3,6 +3,7 @@ package libnmdc
import (
"crypto/tls"
"errors"
"fmt"
"net"
"net/url"
@@ -65,6 +66,7 @@ const (
var rx_protocolMessage *regexp.Regexp
var rx_publicChat *regexp.Regexp
var rx_incomingTo *regexp.Regexp
var ErrNotConnected error = errors.New("Not connected")
func init() {
rx_protocolMessage = regexp.MustCompile("(?ms)^[^|]*|")
@@ -74,6 +76,7 @@ func init() {
type HubConnectionOptions struct {
Address HubAddress
SkipVerifyTLS bool // using a negative verb, because bools default to false
Self UserInfo
NickPassword string
NumEventsToBuffer uint
@@ -92,7 +95,8 @@ type HubConnection struct {
OnEvent chan HubEvent
// Private state
conn net.Conn
conn net.Conn // this is an interface
connValid bool
sentOurHello bool
}
@@ -159,8 +163,12 @@ func (this *HubConnection) userJoined_Full(uinf *UserInfo) {
// Note that protocol messages are transmitted on the caller thread, not from
// any internal libnmdc thread.
func (this *HubConnection) SayRaw(protocolCommand string) error {
if this.connValid {
_, err := this.conn.Write([]byte(protocolCommand))
return err
} else {
return ErrNotConnected
}
}
func parseLock(lock []byte) string {
@@ -326,18 +334,23 @@ func (this *HubConnection) worker() {
if this.conn == nil {
if this.Hco.Address.IsSecure() {
this.conn, err = tls.Dial("tcp", this.Hco.Address.GetHostOnly(), nil)
this.conn, err = tls.Dial("tcp", this.Hco.Address.GetHostOnly(), &tls.Config{
InsecureSkipVerify: this.Hco.SkipVerifyTLS,
})
} else {
this.conn, err = net.Dial("tcp", this.Hco.Address.GetHostOnly())
}
if err == nil {
if err != nil {
this.OnEvent <- HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_CONNECTING}
this.connValid = false
} else {
this.connValid = true
}
}
// Read from socket into our local buffer (blocking)
if this.conn != nil {
if this.connValid {
readBuff := make([]byte, 4096)
nbytes, err = this.conn.Read(readBuff)
if nbytes > 0 {

View File

@@ -0,0 +1,31 @@
A logging service for NMDC hubs.
It logs public chat messages to a file, categorised by months. Binaries are provided for Windows/Linux amd64/i386.
Written in golang
Tags: nmdc
=USAGE=
`$nmdc-log-service -Help
Usage of nmdc-log-service:
-Debug
Print additional information on stdout
-Dir string
Output directory (default ".")
-LogConnectionState
Include connection state changes in log (default true)
-Nick string
Nick (default "nmdc-log-service")
-PMResponse string
Message to respond with on PM (default "This is an automated service. For enquiries, please contact an administrator.")
-Password string
Registered nick password
-Server string
Addresses to connect to (comma-separated)`
=CHANGELOG=
2016-04-02 1.0.0
- Initial public release

View File

@@ -24,22 +24,22 @@ main() {
fi
echo "Building win64..."
GOARCH=amd64 GOOS=windows go build -ldflags -s -o nmdc-log-service.exe
GOARCH=amd64 GOOS=windows go build -a -ldflags -s -o nmdc-log-service.exe
7z a -mx9 nmdc-log-service-${version}-win64.7z nmdc-log-service.exe >/dev/null
rm ./nmdc-log-service.exe
echo "Building win32..."
GOARCH=386 GOOS=windows go build -ldflags -s -o nmdc-log-service.exe
GOARCH=386 GOOS=windows go build -a -ldflags -s -o nmdc-log-service.exe
7z a -mx9 nmdc-log-service-${version}-win32.7z nmdc-log-service.exe >/dev/null
rm ./nmdc-log-service.exe
echo "Building linux64..."
GOARCH=amd64 GOOS=linux go build -ldflags -s -o nmdc-log-service
GOARCH=amd64 GOOS=linux go build -a -ldflags -s -o nmdc-log-service
XZ_OPT=-9 tar caf nmdc-log-service-${version}-linux64.tar.xz nmdc-log-service --owner=0 --group=0
rm ./nmdc-log-service
echo "Building linux32..."
GOARCH=386 GOOS=linux go build -ldflags -s -o nmdc-log-service
GOARCH=386 GOOS=linux go build -a -ldflags -s -o nmdc-log-service
XZ_OPT=-9 tar caf nmdc-log-service-${version}-linux32.tar.xz nmdc-log-service --owner=0 --group=0
rm ./nmdc-log-service

View File

@@ -15,6 +15,7 @@ var BaseDir string = "."
var PMResponse string = ""
var LogConnectionState bool
var DebugMode bool
var VerifyTLS bool
var CharacterMatcher *regexp.Regexp
func init() {
@@ -54,6 +55,7 @@ func HubWorker(addr, nick, password string) {
opts := libnmdc.HubConnectionOptions{
Address: libnmdc.HubAddress(addr),
SkipVerifyTLS: !VerifyTLS,
Self: libnmdc.UserInfo{Nick: nick},
NickPassword: password,
}
@@ -104,6 +106,7 @@ func main() {
flag.BoolVar(&LogConnectionState, "LogConnectionState", true, "Include connection state changes in log")
flag.StringVar(&PMResponse, "PMResponse", "This is an automated service. For enquiries, please contact an administrator.", "Message to respond with on PM")
flag.BoolVar(&DebugMode, "Debug", false, "Print additional information on stdout")
flag.BoolVar(&VerifyTLS, "VerifyTLS", true, "Verify TLS certificates")
flag.Parse()
// Assert dir exists