Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1858dfa102 | |||
| 89b67f8559 | |||
| 649b3dfcab | |||
| ed64887ddc | |||
| 2113139cdc | |||
| 07441628d9 | |||
| 34dd9d515c | |||
| 32f64690c9 | |||
| 3f66cd93c7 | |||
| 9b32682c8a | |||
| c9e95df0df | |||
| a2b94e8724 | |||
| 3dfef302ee | |||
| 611a934a4e | |||
| 1a3617b960 | |||
| a37b1773d0 |
4
.hgtags
4
.hgtags
@@ -3,3 +3,7 @@
|
||||
137c1b65039e03c80379826a6efdfd808f6fbc8f libnmdc-r2
|
||||
d8b64d5527c2a5e4d76872e5bc3d69f7646135c6 libnmdc-r3
|
||||
fca41372e400853775b02e951f9db91d87f41adb nmdc-log-service-1.0.1
|
||||
050b424a7c5d5a27c9323c8810f3afbead1f5b96 libnmdc-r4
|
||||
da9f123633f9c28be6435ed7898139665d4c39d9 nmdc-log-service-1.0.2
|
||||
75a78f6a78f249a2cd8aa3d29f7e5e6319b4e03b libnmdc-r5
|
||||
4116422bb10229d887f9296970a166fa1ef8c5fd nmdc-log-service-1.0.3
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
An NMDC client protocol library for Golang.
|
||||
|
||||
- Channel-based API.
|
||||
- Includes a sample logging client.
|
||||
- Offers both channel-based and synchronous APIs.
|
||||
- Includes a sample logging client using the channel-based API.
|
||||
- This code hosting site isn't (yet) compatible with `go get`.
|
||||
|
||||
Written in golang
|
||||
@@ -9,6 +9,18 @@ Tags: nmdc
|
||||
|
||||
=CHANGELOG=
|
||||
|
||||
2016-04-16 r6
|
||||
- Fix an issue with calling `panic()` on certain types of abnormal network failure
|
||||
|
||||
2016-04-04 r5
|
||||
- Enhancement: Support protocol keepalives
|
||||
- Enhancement: Support hub redirects (`$ForceMove`)
|
||||
|
||||
2016-04-03 r4
|
||||
- Feature: Add synchronous API
|
||||
- Fix an issue with reading HubConnection's state parameter
|
||||
- Fix an issue with buffered protocol commands
|
||||
|
||||
2016-04-03 r3
|
||||
- Feature: Add `SkipVerifyTLS` option
|
||||
- Fix an issue with calling `panic()` if connection failed
|
||||
|
||||
@@ -13,8 +13,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_CLIENT_TAG string = "libnmdc.go"
|
||||
DEFAULT_HUB_NAME string = "(unknown)"
|
||||
DEFAULT_CLIENT_TAG string = "libnmdc.go"
|
||||
DEFAULT_HUB_NAME string = "(unknown)"
|
||||
SEND_KEEPALIVE_EVERY time.Duration = 29 * time.Second
|
||||
)
|
||||
|
||||
type ConnectionState int
|
||||
@@ -314,15 +315,13 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
||||
this.State = CONNECTIONSTATE_CONNECTED
|
||||
}
|
||||
|
||||
case "$UserCommand":
|
||||
// $UserCommand 1 1 Group chat\New group chat$<%[mynick]> !groupchat_new||
|
||||
// TODO
|
||||
|
||||
case "$ForceMove":
|
||||
// TODO
|
||||
this.Hco.Address = HubAddress(commandParts[1])
|
||||
this.conn.Close() // we'll reconnect onto the new address
|
||||
|
||||
// IGNORABLE COMMANDS
|
||||
case "$Supports":
|
||||
case "$UserCommand": // TODO $UserCommand 1 1 Group chat\New group chat$<%[mynick]> !groupchat_new||
|
||||
case "$UserList":
|
||||
case "$OpList":
|
||||
case "$HubTopic":
|
||||
@@ -335,6 +334,20 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
||||
}
|
||||
}
|
||||
|
||||
func CheckIsNetTimeout(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
switch err.(type) {
|
||||
case net.Error:
|
||||
return err.(net.Error).Timeout()
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (this *HubConnection) worker() {
|
||||
var fullBuffer string
|
||||
var err error = nil
|
||||
@@ -370,7 +383,17 @@ func (this *HubConnection) worker() {
|
||||
// Read from socket into our local buffer (blocking)
|
||||
if this.connValid {
|
||||
readBuff := make([]byte, 1024)
|
||||
this.conn.SetReadDeadline(time.Now().Add(SEND_KEEPALIVE_EVERY))
|
||||
nbytes, err = this.conn.Read(readBuff)
|
||||
|
||||
if CheckIsNetTimeout(err) {
|
||||
// No data before read deadline
|
||||
err = nil
|
||||
|
||||
// Send KA packet
|
||||
_, err = this.conn.Write([]byte("|"))
|
||||
}
|
||||
|
||||
if nbytes > 0 {
|
||||
fullBuffer += string(readBuff[0:nbytes])
|
||||
}
|
||||
|
||||
@@ -30,6 +30,18 @@ Usage of nmdc-log-service:
|
||||
|
||||
=CHANGELOG=
|
||||
|
||||
2016-04-16 1.0.4
|
||||
- Enhancement: Upgrade `libnmdc` from `r5` to `r6`
|
||||
- Include a sample systemd unit script in source archive
|
||||
- Fix an issue showing zero connected hubs in user tag
|
||||
- Fix a cosmetic issue with logging repeated identical connection failure messages
|
||||
|
||||
2016-04-04 1.0.3
|
||||
- Enhancement: Upgrade `libnmdc` from `r4` to `r5`
|
||||
|
||||
2016-04-03 1.0.2
|
||||
- Enhancement: Upgrade `libnmdc` from `r3` to `r4`
|
||||
|
||||
2016-04-03 1.0.1
|
||||
- Enhancement: Add `-VerifyTLS` option
|
||||
- Enhancement: Upgrade `libnmdc` from `r2` to `r3`
|
||||
|
||||
@@ -7,6 +7,12 @@ export GOPATH=$(
|
||||
cygpath -w "$(pwd)"
|
||||
)
|
||||
|
||||
sanitise() {
|
||||
local tmp=$(mktemp)
|
||||
cat "$1" | perl -pe 's~C:.Users.......Documents.DEV.~C:/xxxxxxxxxxxxxxxxxxxxxxxxx/~g' > "$tmp"
|
||||
mv "$tmp" "$1"
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
local version=""
|
||||
@@ -25,21 +31,25 @@ main() {
|
||||
|
||||
echo "Building win64..."
|
||||
GOARCH=amd64 GOOS=windows go build -a -ldflags -s -o nmdc-log-service.exe
|
||||
sanitise 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 -a -ldflags -s -o nmdc-log-service.exe
|
||||
sanitise 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 -a -ldflags -s -o nmdc-log-service
|
||||
sanitise 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 -a -ldflags -s -o nmdc-log-service
|
||||
sanitise 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
|
||||
|
||||
|
||||
14
src/nmdc-log-service/hublog.service
Normal file
14
src/nmdc-log-service/hublog.service
Normal file
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=NMDC Log Service
|
||||
|
||||
[Service]
|
||||
Environment=TZ=Etc/UTC
|
||||
Type=simple
|
||||
ExecStart=/home/hublog/nmdc-log-service -Dir /home/hublog/logs/ -Server ... -Nick ... -Password '...' -VerifyTLS=false
|
||||
Restart=always
|
||||
RestartSec=30s
|
||||
User=hublog
|
||||
Group=nogroup
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -51,12 +51,16 @@ func LogMessage(hub, message string) {
|
||||
}
|
||||
}
|
||||
|
||||
func HubWorker(addr, nick, password string) {
|
||||
type HubWorker struct {
|
||||
LastConnectionStateMessage string
|
||||
}
|
||||
|
||||
func (this *HubWorker) MainLoop(addr, nick, password string) {
|
||||
|
||||
opts := libnmdc.HubConnectionOptions{
|
||||
Address: libnmdc.HubAddress(addr),
|
||||
SkipVerifyTLS: !VerifyTLS,
|
||||
Self: libnmdc.UserInfo{Nick: nick},
|
||||
Self: *libnmdc.NewUserInfo(nick),
|
||||
NickPassword: password,
|
||||
}
|
||||
hub := opts.Connect()
|
||||
@@ -71,11 +75,16 @@ func HubWorker(addr, nick, password string) {
|
||||
switch event.EventType {
|
||||
case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
|
||||
if LogConnectionState {
|
||||
str := "* " + event.StateChange.Format()
|
||||
if len(event.Message) > 0 {
|
||||
LogMessage(addr, "* "+event.StateChange.Format()+" ("+event.Message+")")
|
||||
} else {
|
||||
LogMessage(addr, "* "+event.StateChange.Format())
|
||||
str += " (" + event.Message + ")"
|
||||
}
|
||||
|
||||
// Prevent logging the same message repeatedly
|
||||
if str != this.LastConnectionStateMessage {
|
||||
LogMessage(addr, str)
|
||||
}
|
||||
this.LastConnectionStateMessage = str
|
||||
}
|
||||
|
||||
case libnmdc.EVENT_PUBLIC:
|
||||
@@ -135,7 +144,8 @@ func main() {
|
||||
os.MkdirAll(GetDirectoryNameForHub(hubaddr), 0755)
|
||||
|
||||
// Launch logger
|
||||
go HubWorker(hubaddr, *nick, *password)
|
||||
hw := HubWorker{}
|
||||
go hw.MainLoop(hubaddr, *nick, *password)
|
||||
|
||||
launch_ct++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user