This repository has been archived by the owner on Nov 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Features/spring cleanup #41
Open
ghost
wants to merge
83
commits into
BotBotMe:features/flexible_config
Choose a base branch
from
unknown repository
base: features/flexible_config
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
f7380fc
Endpoint cleanup.
bartTC aee0406
Adding some more logging to follow the restarting process
yml 7a7bfec
Fixing a race condition between redis and postgres when we try to REF…
yml ba447d8
A more graceful channel update
yml 72deadd
Move the sleep to avoid the race condition from botbot-bot to botbot-web
yml c31b353
golint
yml 1085310
swap the posgresql driver to a better maintain repo. Set the applicat…
yml 9cecd76
Explicitely setting a MaxOpenConns and MaxIdleConns for the postgesql…
yml e638673
Use redisDB number too.
bartTC ff4d3c0
Merge branch 'master' of https://github.com/BotBotMe/botbot-bot into …
yml c7e33dd
Build go against 1.2 and tip since we are now using some of the newer…
yml 3cb59f5
Merge pull request #13 from BotBotMe/features/better-postgresql-conne…
yml 1bb0ea1
Reduce the time between ping from 5 min to 10s. Try to reconnect afte…
yml eb93611
Merge branch 'features/better-postgresql-connection-handling'
yml 1e752dd
ref #15. re architecture the ircBot.monitor() to reconnect if there i…
yml 792c7f1
ref #15. Fix a potential race condition in the NetworkManager
yml cbdefe8
ref #15. Fix another race condition reported by the runtime.
yml 988592a
ref #15. Reduce the verbosity of the log and improve its readability
yml b9f1f88
refs #15. Improved the logging before reconnecting
yml 0bc1136
refs #15. give a grace period of 3 missed reply to Ping.
yml 1e2b522
ref #15. Increase maxPongWithoutMessage from 15 to 150 to only rejoin…
yml 13ca9c4
Improve the error loging to know which bot cannot write the the socke…
yml 30cbab6
Reconnect a bit more aggresively when the server do not respond to ping
yml e4ba11a
Add expvar and export some stats for each bots
yml 1ea5830
Change the naming of the stats for each bots
yml 79376d0
Remove the nick from the stats name because it seems to upset graphite
yml c087d41
Taking advantage of the new server_identifier to push the stats to gr…
yml e191e8a
Added an expvar to count the received messages from IRC
yml ca09d03
Update README.md
yml aff63d3
Added a goroutine that collect the channels every bot is connected to…
yml 021884e
Merge branch 'master' of https://github.com/BotBotMe/botbot-bot
yml aa66850
Added defer before unlock
vbabiy 11f5442
Fix an issue on the method comparing the channels.
yml 9a464e2
Oups this line should have been deleted in my previous commit
yml ce577dd
Fix a bunch of races in the test suite. Added a Field on the ircBot s…
yml ebbbda0
Use my protected method GotLength() instead of directly taking the le…
yml 0af55d5
Continue to fix race condition in the test suite
yml b39692b
Increate the number of tries before belling out
yml 79286be
An even larger number of tries to support slow server
yml 59801dc
Fixing mock irc server to handle tls connect correctly.
vbabiy d52af7a
Merge branch 'master' into features/fix_races_in_test
vbabiy 1e338c9
improve the ChatBot expvar stats
yml f3a15cb
Enable pprof
vbabiy f4c1d33
Add a .gitignore
vbabiy b5f8157
Move to a buffered channel till we refactor monitor()
vbabiy 1f6c287
Merge branch 'master' into features/better_chatbotStats
yml 1daf637
Itermediary changeset this is an improvement over the exisiting code …
yml 85f4f7c
Break out read socket in to its goroutine
vbabiy f6f313c
Linting. Fix a panic when tring to write a closed bot.socket
yml 18b94d3
Better connect
yml df6576a
Reinitialized the missedPing to 0
yml d2aa030
Fixing monitoring, and backoff.
vbabiy b94758a
Merge branch 'features/better_chatbotStats' of github.com:BotBotMe/bo…
vbabiy 3c884e5
Fixing formatting
vbabiy 0225b08
reverted the changes that aim to change the log library.
yml d67f8d7
move the goroutine to read socket in a more logical place where we ar…
yml 6d3e35b
Move the goroutine whoiscollector and into monitor
yml 51b6acb
Continue to clean up irc.go. Fix a panic when the bot try to reconnec…
yml 5421ff1
Return from the monitor goroutine when we send the reconnect
yml 52fb875
Fxing TestFlood and added a work around to force glog to log the test…
yml 74512b5
Fix a race condition that is expose when running irc_test.
yml a171f31
Fix the test suite
yml 0e6dd3a
Tells travis that it should also run the tests for the sub packages
yml a44b98e
Deactivate the pingTimeout case if we get a response.
yml e03945a
Fix another race in the MockIRCServer implementation.
yml f4aeb20
Cleanup the logging statement use Errorln for error and V(3) for the …
yml aa0aae5
Be stingy with the lock and take the smalest lock possible and releas…
yml 3017443
Continue reduce time spent locking.
yml 6d54ac9
Remove bot.closing from the ircBot struct. I explictely pass around a…
yml 26b6994
Fix the last known race when the bot get disconnected for more than 4…
yml 69ad07c
Merge sender and listen into a single goroutine ListenAndSend
yml 6dd12e3
Fix a deadlock when several gorountines try to get the botstats.
yml 9ab1f49
Double the number of Max open connections to postgres
yml 1ba3ff6
Reduce the time where we are locking the bot in the bot.updateNick
yml abce29c
Temporary remove self.recordUserCounts() from the code base because I…
yml 3205be5
nothing
yml c7909d6
nothing
yml 21edbcb
move ircBot.init() to a not exported name.
yml fbbeb85
Move Connect and ListenAndSend to not exported name.
yml d4591bf
Spring cleanup. Reduce the surface of ircBot. Move ircBot.connect() o…
yml 8fe417b
The reconnect is done at the networkmanager level. More cleanup
yml 7e94c1c
I have commited the integration test because I can't figure out how t…
yml c89f71a
Fix the main integration test by using tls.Listen
yml File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
language: go | ||
|
||
go: | ||
- 1.1 | ||
- 1.2 | ||
- tip | ||
|
||
install: | ||
- go get github.com/BotBotMe/botbot-bot | ||
|
||
script: go test github.com/BotBotMe/botbot-bot | ||
script: go test github.com/BotBotMe/botbot-bot/... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
The certs included in this repo has been with `generate_cert` from the GO | ||
standard library. | ||
|
||
``` | ||
generate_cert -ca=true -duration=8760h0m0s -host="127.0.0.1" -start-date="Jan 1 15:04:05 2014" | ||
``` | ||
|
||
The generate_cert can be build like this | ||
|
||
``` | ||
go build $GOROOT/src/pkg/crypto/tls/generate_cert.go | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIC8zCCAd2gAwIBAgIQLlTIDFFPizKZzJKC6j/k4jALBgkqhkiG9w0BAQswEjEQ | ||
MA4GA1UEChMHQWNtZSBDbzAeFw0xNDAxMDExNTA0MDVaFw0xNTAxMDExNTA0MDVa | ||
MBIxEDAOBgNVBAoTB0FjbWUgQ28wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK | ||
AoIBAQDMVw4BGI1GsAdye8rqiSUS/gOI1oGpdbHO/B99xxXib9VvqFx3pT4WkQdd | ||
OqAni7X4K4Td/3MBQ/K+Wy982wxR3pCHCWRxZ6iDQi/TPMRqP8hSufTyRd/QA+bj | ||
UEXUh4Orq3VthIq0i4TjML9rC14pJy/ldb80clHLoVdx2uz3t52k0VZS1QMwLLpW | ||
l3khpjO7ICUsdfFda+oMbroQPlgSEg69QcBLmwTuxJ7Y2PRVK6nWU/2+fGKQQXGT | ||
PA9jU/zHt/7voUA9I1zXM1s7e1ExRbD4MFlaLwUo0qlbLL0dsIFURiJh3fBvgum/ | ||
T7NQRvEJQQFx25S6/zyxn1VwKcVbAgMBAAGjSTBHMA4GA1UdDwEB/wQEAwIApDAT | ||
BgNVHSUEDDAKBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MA8GA1UdEQQIMAaH | ||
BH8AAAEwCwYJKoZIhvcNAQELA4IBAQA8YZJmhOwIYEhUzObwQQzcJY3ZrUN7AiEc | ||
sQnFaqOmzrtP0SDjWPlMITXeHV84Zw5+taIv1OQ3IyG9z+BPgIAkHQYVuVILrYOU | ||
nVGs9bxdcrhKLwKVXEUoRsa+FY3NG8r7HTO+jYveXoXBjqA3NT7CmlJ3QtJJiCD/ | ||
5S5u1KwfAZQ7xcrigBxTyRSpR/m0APGDGqrf5mKUcQVkGF9RIEDWOuCoqr1He9GZ | ||
ba6HNYeEQrsdooazi9xbR2bk6F0Wa2Pt4YpS5Zy3KVuhxwbo43houwifhjF23MM/ | ||
4DmoVl1copKHf/dMSsiDbGDeF2g/Z6Q2X790ijDOnxkOEbpjyuHP | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEpAIBAAKCAQEAzFcOARiNRrAHcnvK6oklEv4DiNaBqXWxzvwffccV4m/Vb6hc | ||
d6U+FpEHXTqgJ4u1+CuE3f9zAUPyvlsvfNsMUd6QhwlkcWeog0Iv0zzEaj/IUrn0 | ||
8kXf0APm41BF1IeDq6t1bYSKtIuE4zC/awteKScv5XW/NHJRy6FXcdrs97edpNFW | ||
UtUDMCy6Vpd5IaYzuyAlLHXxXWvqDG66ED5YEhIOvUHAS5sE7sSe2Nj0VS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+PuoL0ekzP0f5WVHhkgaQHRyPDFCCX4rSX7tK | ||
ivKYIyhXRvTvbzUd//MMDNr2SwqiDCidXnQpRzxGFuZOUaohk0u2PDOmVnqfTBoR | ||
9xMmDYYKXdi7LBlKFzZxPcsRcZXwFk/vmpF0kh9VvjltA4h0eUUng7DZFuSc0kZT | ||
nC3C5QKBgQCfg1NASP4WsANzaLABzfDKbQ23pxb9eqBWGVESEPhzUoqiTZ0rSDl4 | ||
5oY7Dx9RGIJxPQWoG3nxjAK3GnlArUEJf4S/YMFmOX0naXp4HW4RxODPNoxnaQG0 | ||
NfDb7xAuQNgY2F5T9dK02EPJ0tamsJbvHxVZLm1eiU2HPcK1ZurRfw== | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,65 @@ package common | |
|
||
import ( | ||
"bufio" | ||
"net" | ||
"crypto/tls" | ||
"flag" | ||
"log" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/golang/glog" | ||
) | ||
|
||
// SetGlogFlags walk around a glog issue and force it to log to stderr. | ||
// It need to be called at the beginning of each test. | ||
func SetGlogFlags() { | ||
flag.Set("alsologtostderr", "true") | ||
flag.Set("V", "3") | ||
} | ||
|
||
// MockSocket is a dummy implementation of ReadWriteCloser | ||
type MockSocket struct { | ||
sync.RWMutex | ||
Counter chan bool | ||
Receiver chan string | ||
} | ||
|
||
func (sock MockSocket) Write(data []byte) (int, error) { | ||
glog.V(3).Infoln("[Debug]: Starting MockSocket.Write of:", string(data)) | ||
if sock.Counter != nil { | ||
sock.Counter <- true | ||
} | ||
if sock.Receiver != nil { | ||
sock.Receiver <- string(data) | ||
} | ||
|
||
return len(data), nil | ||
} | ||
|
||
func (sock MockSocket) Read(into []byte) (int, error) { | ||
sock.RLock() | ||
defer sock.RUnlock() | ||
time.Sleep(time.Second) // Prevent busy loop | ||
return 0, nil | ||
} | ||
|
||
func (sock MockSocket) Close() error { | ||
if sock.Receiver != nil { | ||
close(sock.Receiver) | ||
} | ||
if sock.Counter != nil { | ||
close(sock.Counter) | ||
} | ||
return nil | ||
} | ||
|
||
/* | ||
* Mock IRC server | ||
*/ | ||
|
||
type MockIRCServer struct { | ||
sync.RWMutex | ||
Port string | ||
Message string | ||
Got []string | ||
|
@@ -24,44 +74,63 @@ func NewMockIRCServer(msg, port string) *MockIRCServer { | |
} | ||
} | ||
|
||
func (self *MockIRCServer) Run(t *testing.T) { | ||
func (srv *MockIRCServer) GotLength() int { | ||
srv.RLock() | ||
defer srv.RUnlock() | ||
return len(srv.Got) | ||
} | ||
|
||
listener, err := net.Listen("tcp", ":"+self.Port) | ||
func (srv *MockIRCServer) Run(t *testing.T) { | ||
// Use the certs generated with generate_certs | ||
cert, err := tls.LoadX509KeyPair("certs/cert.pem", "certs/key.pem") | ||
if err != nil { | ||
t.Error("Error starting mock server on "+self.Port, err) | ||
return | ||
log.Fatalf("server: loadkeys: %s", err) | ||
} | ||
|
||
// Accept a single connection | ||
conn, lerr := listener.Accept() | ||
if lerr != nil { | ||
t.Error("Error on IRC server on Accept. ", err) | ||
config := tls.Config{Certificates: []tls.Certificate{cert}} | ||
listener, err := tls.Listen("tcp", "127.0.0.1:"+srv.Port, &config) | ||
if err != nil { | ||
t.Error("Error starting mock server on "+srv.Port, err) | ||
return | ||
} | ||
|
||
// First message triggers BotBot to send USER and NICK messages | ||
conn.Write([]byte(":hybrid7.debian.local NOTICE AUTH :*** Looking up your hostname...\n")) | ||
|
||
// Ask for NickServ auth, and pretend we got it | ||
conn.Write([]byte(":NickServ!NickServ@services. NOTICE graham_king :This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <password>\n")) | ||
conn.Write([]byte(":NickServ!NickServ@services. NOTICE graham_king :You are now identified for graham_king.\n")) | ||
for { | ||
conn, lerr := listener.Accept() | ||
// If create a new connection throw the old data away | ||
// This can happen if a client trys to connect with tls | ||
// Got will store the handshake data. The cient will try | ||
// connect with a plaintext connect after the tls fails. | ||
srv.Lock() | ||
srv.Got = make([]string, 0) | ||
srv.Unlock() | ||
|
||
conn.Write([]byte(":wolfe.freenode.net 001 graham_king :Welcome to the freenode Internet Relay Chat Network graham_king\n")) | ||
if lerr != nil { | ||
t.Error("Error on IRC server on Accept. ", err) | ||
} | ||
|
||
// This should get sent to plugins | ||
conn.Write([]byte(":[email protected] PRIVMSG #unit :" + self.Message + "\n")) | ||
//conn.Write([]byte("test: " + self.Message + "\n")) | ||
// First message triggers BotBot to send USER and NICK messages | ||
conn.Write([]byte(":hybrid7.debian.local NOTICE AUTH :*** Looking up your hostname...\n")) | ||
// Ask for NickServ auth, and pretend we got it | ||
conn.Write([]byte(":NickServ!NickServ@services. NOTICE graham_king :This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <password>\n")) | ||
conn.Write([]byte(":NickServ!NickServ@services. NOTICE graham_king :You are now identified for graham_king.\n")) | ||
conn.Write([]byte(":wolfe.freenode.net 001 graham_king :Welcome to the freenode Internet Relay Chat Network graham_king\n")) | ||
// This should get sent to plugins | ||
conn.Write([]byte(":[email protected] PRIVMSG #unit :" + srv.Message + "\n")) | ||
conn.Write([]byte("test: " + srv.Message + "\n")) | ||
|
||
var derr error | ||
var data []byte | ||
var derr error | ||
var data []byte | ||
|
||
bufRead := bufio.NewReader(conn) | ||
for { | ||
data, derr = bufRead.ReadBytes('\n') | ||
if derr != nil { | ||
// Client closed connection | ||
break | ||
bufRead := bufio.NewReader(conn) | ||
for { | ||
data, derr = bufRead.ReadBytes('\n') | ||
if derr != nil { | ||
// Client closed connection | ||
break | ||
} | ||
srv.Lock() | ||
srv.Got = append(srv.Got, string(data)) | ||
srv.Unlock() | ||
} | ||
self.Got = append(self.Got, string(data)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this was unintentional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the author, but as noted above, it's a self-signed cert, probably used for testing. It isn't used for anything in production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just seems overall that it would be better to just leave the readme explaining how to get here rather than distributing a default cert even if the intention is for testing.