61 Commits

Author SHA1 Message Date
dependabot-preview[bot]
eea24e3047 Bump golang.org/x/text from 0.3.3 to 0.3.4 (#79)
Bumps [golang.org/x/text](https://github.com/golang/text) from 0.3.3 to 0.3.4.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](https://github.com/golang/text/compare/v0.3.3...v0.3.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-10-28 08:09:40 +10:00
dependabot-preview[bot]
e91312a468 Bump github.com/sirupsen/logrus from 1.6.0 to 1.7.0 (#78)
Bumps [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) from 1.6.0 to 1.7.0.
- [Release notes](https://github.com/sirupsen/logrus/releases)
- [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sirupsen/logrus/compare/v1.6.0...v1.7.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-10-15 16:51:36 +10:00
dependabot-preview[bot]
065a93d56f Bump github.com/imdario/mergo from 0.3.9 to 0.3.11 (#77)
Bumps [github.com/imdario/mergo](https://github.com/imdario/mergo) from 0.3.9 to 0.3.11.
- [Release notes](https://github.com/imdario/mergo/releases)
- [Commits](https://github.com/imdario/mergo/compare/v0.3.9...v0.3.11)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-08-13 22:49:43 +10:00
dependabot-preview[bot]
fbbf36d1a1 Bump golang.org/x/text from 0.3.2 to 0.3.3 (#74)
Bumps [golang.org/x/text](https://github.com/golang/text) from 0.3.2 to 0.3.3.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](https://github.com/golang/text/compare/v0.3.2...v0.3.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-06-17 14:40:05 +10:00
James Mills
3675251706 Refactored user flag/modes and fixed several data race bugs 2020-06-08 14:40:22 +10:00
James Mills
6f61b673a1 Refactor client 2020-06-08 14:20:21 +10:00
James Mills
4566b2021f Tidied up unused dependencies 2020-06-08 13:56:51 +10:00
James Mills
e7c5b96a6a Updated depednenices 2020-06-08 13:56:36 +10:00
James Mills
b18403ea71 Migrate to Github Actions Workflows 2020-06-08 13:47:06 +10:00
dependabot-preview[bot]
c9cbab6769 Bump github.com/stretchr/testify from 1.5.1 to 1.6.0 (#72)
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.5.1 to 1.6.0.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.5.1...v1.6.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-06-01 11:21:26 +10:00
dependabot-preview[bot]
176aba3c99 Bump gopkg.in/yaml.v2 from 2.2.8 to 2.3.0 (#68)
Bumps [gopkg.in/yaml.v2](https://github.com/go-yaml/yaml) from 2.2.8 to 2.3.0.
- [Release notes](https://github.com/go-yaml/yaml/releases)
- [Commits](https://github.com/go-yaml/yaml/compare/v2.2.8...v2.3.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-05-13 11:45:36 +10:00
dependabot-preview[bot]
d814c48dce Bump github.com/stretchr/testify from 1.3.0 to 1.5.1 (#67)
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.3.0 to 1.5.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.3.0...v1.5.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-05-06 11:56:10 +10:00
dependabot-preview[bot]
3af82e3e8e Bump golang.org/x/text from 0.3.0 to 0.3.2 (#56)
Bumps [golang.org/x/text](https://github.com/golang/text) from 0.3.0 to 0.3.2.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](https://github.com/golang/text/compare/v0.3.0...v0.3.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: James Mills <prologic@shortcircuit.net.au>
2020-05-05 15:10:46 +10:00
dependabot-preview[bot]
8a8d7b1e97 Bump github.com/prometheus/client_golang from 0.9.2 to 0.9.4 (#58)
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 0.9.2 to 0.9.4.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v0.9.2...v0.9.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: James Mills <prologic@shortcircuit.net.au>
2020-05-05 15:09:36 +10:00
dependabot-preview[bot]
2ac33b7d2c Bump gopkg.in/yaml.v2 from 2.2.2 to 2.2.8 (#60)
Bumps [gopkg.in/yaml.v2](https://github.com/go-yaml/yaml) from 2.2.2 to 2.2.8.
- [Release notes](https://github.com/go-yaml/yaml/releases)
- [Commits](https://github.com/go-yaml/yaml/compare/v2.2.2...v2.2.8)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: James Mills <prologic@shortcircuit.net.au>
2020-05-05 15:08:30 +10:00
dependabot-preview[bot]
a54031de9e Bump github.com/stretchr/testify from 1.2.2 to 1.5.1 (#62)
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.2.2 to 1.5.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.2.2...v1.5.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: James Mills <prologic@shortcircuit.net.au>
2020-05-05 15:08:14 +10:00
dependabot-preview[bot]
a49dea57d8 Bump github.com/imdario/mergo from 0.3.6 to 0.3.9 (#65)
Bumps [github.com/imdario/mergo](https://github.com/imdario/mergo) from 0.3.6 to 0.3.9.
- [Release notes](https://github.com/imdario/mergo/releases)
- [Commits](https://github.com/imdario/mergo/compare/v0.3.6...v0.3.9)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: James Mills <prologic@shortcircuit.net.au>
2020-05-05 15:07:20 +10:00
dependabot-preview[bot]
114c6aa80c Bump github.com/sirupsen/logrus from 1.2.0 to 1.6.0 (#66)
Bumps [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) from 1.2.0 to 1.6.0.
- [Release notes](https://github.com/sirupsen/logrus/releases)
- [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sirupsen/logrus/compare/v1.2.0...v1.6.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-05-05 15:06:41 +10:00
James Mills
414c2fcf89 Added DependaBot config 2019-12-26 14:03:06 +10:00
James Mills
9d860692fa Update Drone CI config 2018-12-31 20:11:21 +10:00
James Mills
98cb66559a Migrate to Drone CI, Codecov and Go11Modules 2018-12-31 20:08:19 +10:00
James Mills
e14795818f Add related projects 2018-11-27 05:49:17 +10:00
James Mills
c394ea6735 Set theme jekyll-theme-architect 2018-11-27 05:41:33 +10:00
James Mills
c94884fb9f Add webhook for local CI 2018-05-19 14:00:00 -07:00
James Mills
784039998f Fixed local CI notify email settings 2018-05-19 13:35:25 -07:00
James Mills
6981b10763 Create PULL_REQUEST_TEMPLATE.md 2018-05-19 13:21:30 -07:00
James Mills
d170e01d38 Update issue templates 2018-05-19 13:20:24 -07:00
James Mills
5787059d11 Create CODE_OF_CONDUCT.md (#50) 2018-05-19 13:19:01 -07:00
James Mills
2e4ff30276 Add more recommended clients 2018-05-19 13:16:29 -07:00
James Mills
f18765a41a Add more recommended clients 2018-05-19 13:14:03 -07:00
James Mills
d23f7cf93d Reconfigure email notify rule for local CI 2018-05-19 12:51:15 -07:00
James Mills
6d64a46466 Updated 3rd-party vendored packages 2018-05-19 12:37:47 -07:00
James Mills
14ed3a6633 Fixed README 2018-05-19 10:25:44 -07:00
James Mills
cb46494733 Fixed build 2018-05-19 00:28:55 -07:00
James Mills
e3fea6c97b Fixed concurrent access to and data race on client.hasQuit 2018-05-19 00:01:14 -07:00
James Mills
9b70d25143 Add tests for metrics 2018-05-18 23:42:19 -07:00
James Mills
7a20037194 Disabled and commented out a recey test that still needs fixing 2018-05-18 23:31:03 -07:00
James Mills
5fa7214853 Fixed concurrent access to internl metrics maps 2018-05-18 23:30:43 -07:00
James Mills
e905b44fb4 Don't nilify the channel on closure (select will block indefinately) 2018-05-18 22:59:07 -07:00
James Mills
84a36a0095 Remove SIGQUIT and SIGHUP signals 2018-05-18 22:46:11 -07:00
James Mills
aa4907d8ae Add bench and profile targets 2018-05-18 22:34:09 -07:00
James Mills
facfcba232 Add grafana dashboard 2018-05-02 02:40:52 -07:00
James Mills
d3285748f9 Remove silly build token in version and add goreleaser config 2017-12-28 00:53:46 -08:00
Kevin Zita
283ef104a4 Aded support for HostMask user mode (+x) (#47) 2017-12-28 00:36:13 -08:00
James Mills
04d907d1e9 Fixed typo in README 2017-12-14 00:13:29 -08:00
James Mills
d74a6780fe Fixed writeloop goroutine leadk (#45) 2017-12-14 00:02:07 -08:00
James Mills
d7e9ef230a Refactored e2e integration tests 2017-12-06 20:59:04 -08:00
James Mills
75f224a7c0 Improves coverage of integreation tests to 40% (#42)
* Added TestChannel_PRIVMSG test

* Refactored integration testing framework for better timtouts and added TestChannel_InviteOnly test

* Try to fix TestChannel_PRIVMSG test

* Fuck it

* Added TestChannel_NoExternal test

* Added TestChannel_BadChannelKey and TestChannel_GoodChannelKey tests

* Bah humbut

* Update vendored 3rd-party deps

* Removed use of deadlock sync package

* Fix all tests :D yay

* Added some topic tests

* Add TestSASL
2017-12-06 02:19:27 -08:00
James Mills
caab002d51 Relase v1.6.4 2017-12-02 18:58:00 -08:00
James Mills
7ff892bba9 Added Drone CI test step 2017-12-02 18:56:53 -08:00
James Mills
233238b709 Adds a basic integration test suite framework (#38)
* Added a basic integration test suite framework

* Add TestConnect_RplWelcome test

* Update vendor 3rd-party deps for missing github.com/stretchr/testify/assert

* Add TestUser_PRIVMSG test

* Rename some tests

* Moar tests

* New test framework with better reliability
2017-11-28 02:15:30 -08:00
James Mills
59e0792db1 Fixed bad label value when bumping metrics for commands processed (#40) 2017-11-27 23:57:42 -08:00
James Mills
962b6645c1 Release v1.6.3 2017-11-27 19:18:58 -08:00
James Mills
cee8bf9957 Added support for multi-layer channel privacy (Public, Private and Secret) (#36) 2017-11-27 19:16:17 -08:00
James Mills
9d93bca179 Added support for measuring secure vs. non-secure registerd clients (#34) 2017-11-26 17:31:11 -08:00
James Mills
ccae795335 Fixed graceful shutdown (#32) 2017-11-26 17:30:53 -08:00
James Mills
862eb429d4 Update README.md 2017-11-26 15:26:12 -08:00
James Mills
9e075dde67 Fixed send on closed channel bug (#29) 2017-11-26 13:25:21 -08:00
James Mills
20be29bcef Fixed bug with RPL_ENDOFWHOIS (/WHOIS) response missing nick component (#27) 2017-11-26 10:42:14 -08:00
James Mills
34c3be0a88 Update README.md 2017-11-26 10:10:18 -08:00
Mike Taylor
be246a3bc4 minor typo fixes (#25) 2017-11-25 20:21:54 -08:00
55 changed files with 2835 additions and 335 deletions

8
.dependabot/config.yml Normal file
View File

@@ -0,0 +1,8 @@
version: 1
update_configs:
- package_manager: "go:modules"
directory: "/"
update_schedule: "daily"
- package_manager: "docker"
directory: "/"
update_schedule: "weekly"

View File

@@ -1,30 +0,0 @@
workspace:
base: /go
path: src/github.com/prologic/eris
pipeline:
build:
image: golang
commands:
- go get -d
- go build .
docker:
image: plugins/docker
repo: r.mills.io/prologic/eris
registry: r.mills.io
secrets: [ docker_username, docker_password ]
notify:
image: drillster/drone-email
host: mail.mills.io
from: drone@mills.io
skip_verify: true
when:
status: [ success, changed, failure ]
secrets:
registry_username:
external: true
registry_password:
external: true

35
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@@ -0,0 +1,35 @@
---
name: Bug report
about: Create a report to help us improve
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.

View File

@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

35
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
---
name: Build
on:
push:
branches:
- master
pull_request:
jobs:
build:
name: Build
strategy:
matrix:
go-version:
- "1.12.x"
- "1.13.x"
- "1.14.x"
os:
- "ubuntu-latest"
- "macos-latest"
- "windows-latest"
runs-on: ${{ matrix.os }}
steps:
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
id: go
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: |
go build -v .
- name: Test
run: |
go test -v -race .

9
.gitignore vendored
View File

@@ -1,6 +1,9 @@
*~* *~
bin
*.db *.db
*.bak
*.pem *.pem
eris /bin
/dist
/eris
/coverage.txt

51
.gitmodules vendored
View File

@@ -1,51 +0,0 @@
[submodule "vendor/github.com/sirupsen/logrus"]
path = vendor/github.com/sirupsen/logrus
url = https://github.com/sirupsen/logrus
[submodule "vendor/golang.org/x/crypto"]
path = vendor/golang.org/x/crypto
url = https://go.googlesource.com/crypto
[submodule "vendor/golang.org/x/sys"]
path = vendor/golang.org/x/sys
url = https://go.googlesource.com/sys
[submodule "vendor/github.com/DanielOaks/girc-go"]
path = vendor/github.com/DanielOaks/girc-go
url = https://github.com/DanielOaks/girc-go
[submodule "vendor/github.com/goshuirc/e-nfa"]
path = vendor/github.com/goshuirc/e-nfa
url = https://github.com/goshuirc/e-nfa
[submodule "vendor/github.com/imdario/mergo"]
path = vendor/github.com/imdario/mergo
url = https://github.com/imdario/mergo
[submodule "vendor/golang.org/x/text"]
path = vendor/golang.org/x/text
url = https://go.googlesource.com/text
[submodule "vendor/gopkg.in/yaml.v2"]
path = vendor/gopkg.in/yaml.v2
url = https://gopkg.in/yaml.v2
[submodule "vendor/github.com/prometheus/client_golang"]
path = vendor/github.com/prometheus/client_golang
url = https://github.com/prometheus/client_golang
[submodule "vendor/github.com/beorn7/perks"]
path = vendor/github.com/beorn7/perks
url = https://github.com/beorn7/perks
[submodule "vendor/github.com/golang/protobuf"]
path = vendor/github.com/golang/protobuf
url = https://github.com/golang/protobuf
[submodule "vendor/github.com/prometheus/client_model"]
path = vendor/github.com/prometheus/client_model
url = https://github.com/prometheus/client_model
[submodule "vendor/github.com/prometheus/common"]
path = vendor/github.com/prometheus/common
url = https://github.com/prometheus/common
[submodule "vendor/github.com/matttproud/golang_protobuf_extensions"]
path = vendor/github.com/matttproud/golang_protobuf_extensions
url = https://github.com/matttproud/golang_protobuf_extensions
[submodule "vendor/github.com/prometheus/procfs"]
path = vendor/github.com/prometheus/procfs
url = https://github.com/prometheus/procfs
[submodule "vendor/github.com/sasha-s/go-deadlock"]
path = vendor/github.com/sasha-s/go-deadlock
url = https://github.com/sasha-s/go-deadlock
[submodule "vendor/github.com/petermattis/goid"]
path = vendor/github.com/petermattis/goid
url = https://github.com/petermattis/goid

31
.goreleaser.yml Normal file
View File

@@ -0,0 +1,31 @@
builds:
- binary: eris
flags: -tags "static_build"
ldflags: -w -X mail.Version={{.Version}} -X main.Commit={{.Commit}}
env:
- CGO_ENABLED=0
goos:
- darwin
- freebsd
- linux
- windows
goarch:
- i386
- amd64
- arm
- amd64
goarm:
- 6
- 7
sign:
artifacts: checksum
archive:
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
files:
- "*.pem"
- "*.yml"
- "LICENSE"
- "README.md"

View File

@@ -1,8 +0,0 @@
language: go
sudo: false
go:
- tip
before_install:
- go get github.com/mattn/goveralls
script:
- $HOME/gopath/bin/goveralls -service=travis-ci

29
.yamllint.yml Normal file
View File

@@ -0,0 +1,29 @@
---
yaml-files:
- '*.yaml'
- '*.yml'
- '.yamllint'
rules:
braces: enable
brackets: enable
colons: enable
commas: enable
comments: disable
comments-indentation: disable
document-end: disable
document-start:
level: warning
empty-lines: enable
empty-values: disable
hyphens: enable
indentation: enable
key-duplicates: enable
key-ordering: disable
line-length: disable
new-line-at-end-of-file: enable
new-lines: enable
octal-values: enable
quoted-strings: disable
trailing-spaces: enable
truthy: disable

46
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at prologic@shortcircuit.net.au. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View File

@@ -46,4 +46,4 @@ $ git push -u origin my-feature
When describing your bug report; please be concise and as detailed as you can When describing your bug report; please be concise and as detailed as you can
so we can easily work out what the problem is. It's also very helpful if you so we can easily work out what the problem is. It's also very helpful if you
are able to provide a test case that repeatedly demonstrates the bug at hand: are able to provide a test case that repeatedly demonstrates the bug at hand.

View File

@@ -2,7 +2,6 @@
FROM golang:alpine AS build FROM golang:alpine AS build
ARG TAG ARG TAG
ARG BUILD
ENV APP eris ENV APP eris
ENV REPO prologic/$APP ENV REPO prologic/$APP
@@ -12,7 +11,7 @@ RUN apk add --update git make build-base && \
WORKDIR /go/src/github.com/$REPO WORKDIR /go/src/github.com/$REPO
COPY . /go/src/github.com/$REPO COPY . /go/src/github.com/$REPO
RUN make TAG=$TAG BUILD=$BUILD build RUN make TAG=$TAG build
# Runtime # Runtime
FROM alpine FROM alpine

View File

@@ -6,7 +6,6 @@ APP=eris
PACKAGE=irc PACKAGE=irc
REPO?=prologic/$(APP) REPO?=prologic/$(APP)
TAG?=latest TAG?=latest
BUILD?=dev
all: dev all: dev
@@ -17,17 +16,24 @@ deps:
@go get ./... @go get ./...
build: clean deps build: clean deps
@echo " -> Building $(TAG)$(BUILD)" @echo "github.com/$(REPO)/${PACKAGE}.GitCommit=$(COMMIT)"
@echo " -> Building $(REPO) $(TAG)@$(COMMIT)"
@go build -tags "netgo static_build" -installsuffix netgo \ @go build -tags "netgo static_build" -installsuffix netgo \
-ldflags "-w -X github.com/$(REPO)/${PACKAGE}.GitCommit=$(COMMIT) -X github.com/$(REPO)/${PACKAGE}.Build=$(BUILD)" . -ldflags "-w -X github.com/$(REPO)/${PACKAGE}.GitCommit=$(COMMIT)"
@echo "Built $$(./$(APP) -v)" @echo "Built $$(./$(APP) -v)"
image: image:
@docker build --build-arg TAG=$(TAG) --build-arg BUILD=$(BUILD) -t $(REPO):$(TAG) . @docker build --build-arg TAG=$(TAG) -t $(REPO):$(TAG) .
@echo "Image created: $(REPO):$(TAG)" @echo "Image created: $(REPO):$(TAG)"
profile:
@go test -cpuprofile cpu.prof -memprofile mem.prof -v -bench ./...
bench:
@go test -v -bench ./...
test: test:
@go test -v -cover -race $(TEST_ARGS) @go test -v -cover -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... -race ./...
clean: clean:
@rm -rf $(APP) @git clean -f -d -X

3
PULL_REQUEST_TEMPLATE.md Normal file
View File

@@ -0,0 +1,3 @@
<one line description here>
Fixes #xx

View File

@@ -1,10 +1,10 @@
# eris - IRC Server / Daemon written in Go eris - IRC Server / Daemon written in Go
[![Build Status](https://travis-ci.org/prologic/eris.svg)](https://travis-ci.org/prologic/eris) [![Build Status](https://cloud.drone.io/api/badges/prologic/eris/status.svg)](https://cloud.drone.io/prologic/eris)
[![Go Report Card](https://goreportcard.com/badge/github.com/prologic/eris)](https://goreportcard.com/report/github.com/prologic/eris) [![CodeCov](https://codecov.io/gh/prologic/eris/branch/master/graph/badge.svg)](https://codecov.io/gh/prologic/eris)
[![Coverage](https://coveralls.io/repos/prologic/eris/badge.svg)](https://coveralls.io/r/prologic/eris) [![Go Report Card](https://goreportcard.com/badge/prologic/eris)](https://goreportcard.com/report/prologic/eris)
[![GoDoc](https://godoc.org/github.com/prologic/eris?status.svg)](https://godoc.org/github.com/prologic/eris) [![GoDoc](https://godoc.org/github.com/prologic/eris?status.svg)](https://godoc.org/github.com/prologic/eris)
[![Wiki](https://img.shields.io/badge/docs-wiki-blue.svg)](https://github.com/prologic/eris/wiki) [![Sourcegraph](https://sourcegraph.com/github.com/prologic/eris/-/badge.svg)](https://sourcegraph.com/github.com/prologic/eris?badge)
> This project and repository is based off of [ergonomadic](https://github.com/edmund-huber/ergonomadic) > This project and repository is based off of [ergonomadic](https://github.com/edmund-huber/ergonomadic)
> and much of my original contributions were made in my [fork of ergonomadic](https://github.com/prologic/ergonomadic) > and much of my original contributions were made in my [fork of ergonomadic](https://github.com/prologic/ergonomadic)
@@ -25,7 +25,7 @@ The connotation here is that IRC (*Internet Relay Chat*) is a place of chaos,
strife and discord. IRC is a place where you argue and get into arguments for strife and discord. IRC is a place where you argue and get into arguments for
the sake of argument. the sake of argument.
So `eris` is an IRC daemon written from scratch in Go to factiliate discord So `eris` is an IRC daemon written from scratch in Go to facilitate discord
and have arguments for the sake of argument! and have arguments for the sake of argument!
Pull requests and issues are welcome. Pull requests and issues are welcome.
@@ -35,9 +35,9 @@ Discussion at:
* /server irc.mills.io +6697 (*use TLS/SSL*) * /server irc.mills.io +6697 (*use TLS/SSL*)
* /join #lobby * /join #lobby
Or (*not recommended*)P Or (**not recommended**):
* /server irc.mills.io (*default port 6667, non-TLS) * /server irc.mills.io (*default port 6667, non-TLS*)
* /join #lobby * /join #lobby
## Features ## Features
@@ -54,6 +54,7 @@ Or (*not recommended*)P
* Simple IRC operator privileges (*overrides most things*) * Simple IRC operator privileges (*overrides most things*)
* Secure connection tracking (+z) and SecureOnly user mode (+Z) * Secure connection tracking (+z) and SecureOnly user mode (+Z)
* Secure channels (+Z) * Secure channels (+Z)
* Three layers of channel privacy, Public, Private (+p) and Secret (s)
## Quick Start ## Quick Start
@@ -135,15 +136,45 @@ You may want to customize the configuration however and create your own image ba
$ docker stack deploy -c docker-compose.yml eris $ docker stack deploy -c docker-compose.yml eris
``` ```
Which assumes a `ircd.yml` coniguration fiel int he current directory which Docker will use to distribute as the configuration. The `docker-compose.yml` (*Docker Stackfile*) is available at the root of this repository. Which assumes a `ircd.yml` coniguration file in the current directory which Docker will use to distribute as the configuration. The `docker-compose.yml` (*Docker Stackfile*) is available at the root of this repository.
## Related Proejcts ## Related Projects
There are a number of supported accompanying services that are being developed alongside Eris: There are a number of supported accompanying services that are being developed alongside Eris:
* [Soter](https://github.com/prologic/soter) -- An IRC Bot that persists channel modes and topics. * [Soter](https://github.com/prologic/soter) -- An IRC Bot that persists channel modes and topics.
* [Cadmus](https://github.com/prologic/cadmus) -- An IRC Bot that logs channels and provides an interface for viewing and searching logs * [Cadmus](https://github.com/prologic/cadmus) -- An IRC Bot that logs channels and provides an interface for viewing and searching logs
## Recommended Clients
### CLI / Terminal
* [irccat](https://github.com/prologic/irccat)
* [irssi](https://irssi.org/)
### Cloud
* [IRCCloud](https://www.irccloud.com/)
### Desktop
* [HexChat (Linux)](https://hexchat.github.io/)
* [Textual (OSX)](https://www.codeux.com/textual/)
* [mIRC (Windows)](https://www.mirc.com/)
### Mobile
* [Palaver (iOS)](https://palaverapp.com/) -- SASL, TLS, Server Password, Push Notifications, IRCv3 (*Also supports custom image upload service(s) for better privacy of shared photos/images over IRC*)
### Web
* [Dispatch](https://github.com/khlieng/dispatch) -- TLS, Multiple Servers and Users, Client Certificates
## Related Projects
* [cadmus](https://github.com/prologic/cadmus) -- an IRC Bot written in Go that logs IRC Channels and provides an interface to view and search those logs
* [soter](https://github.com/prologic/soter) -- an IRC Bot written in Go that protects IRC Channels by persisting channel modes and topics
## License ## License
eris is licensed under the MIT License. eris is licensed under the MIT License.

1
_config.yml Normal file
View File

@@ -0,0 +1 @@
theme: jekyll-theme-architect

19
go.mod Normal file
View File

@@ -0,0 +1,19 @@
module github.com/prologic/eris
go 1.14
require (
github.com/DanielOaks/girc-go v0.0.0-20180430075055-8d136c4f9287
github.com/google/uuid v1.1.0 // indirect
github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940 // indirect
github.com/imdario/mergo v0.3.11
github.com/mmcloughlin/professor v0.0.0-20170922221822-6b97112ab8b3
github.com/prometheus/client_golang v0.9.4
github.com/renstrom/shortuuid v3.0.0+incompatible
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.6.0
github.com/thoj/go-ircevent v0.0.0-20180816043103-14f3614f28c3
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
golang.org/x/text v0.3.4
gopkg.in/yaml.v2 v2.3.0
)

100
go.sum Normal file
View File

@@ -0,0 +1,100 @@
github.com/DanielOaks/girc-go v0.0.0-20180430075055-8d136c4f9287 h1:xOE8jDDulcwdPG+coLps6seNn6yERt5xgKSATNqWUM0=
github.com/DanielOaks/girc-go v0.0.0-20180430075055-8d136c4f9287/go.mod h1:nn+Gr++RLey8iGwfvI84UO5oZal6Muz7qPxDII0BsQ8=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s=
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940 h1:KmRLPRstEJiE/9OjumKqI8Rccip8Qmyw2FwyTFxtVqs=
github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940/go.mod h1:VOmrX6cmj7zwUeexC9HzznUdTIObHqIXUrWNYS+Ik7w=
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mmcloughlin/professor v0.0.0-20170922221822-6b97112ab8b3 h1:2YMbJ6WbdQI9K73chxh9OWMDsZ2PNjAIRGTonp3T0l0=
github.com/mmcloughlin/professor v0.0.0-20170922221822-6b97112ab8b3/go.mod h1:LQkXsHRSPIEklPCq8OMQAzYNS2NGtYStdNE/ej1oJU8=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.4 h1:Y8E/JaaPbmFSW2V81Ab/d8yZFYQQGbni1b1jPcG9Y6A=
github.com/prometheus/client_golang v0.9.4/go.mod h1:oCXIBxdI62A4cR6aTRJCgetEjecSIYzOEaeAn4iYEpM=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.4.1 h1:K0MGApIoQvMw27RTdJkPbr3JZ7DNbtxQNyi5STVM6Kw=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2 h1:6LJUbpNm42llc4HRCuvApCSWB/WfhuNo9K98Q9sNGfs=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/renstrom/shortuuid v3.0.0+incompatible h1:F6T1U7bWlI3FTV+JE8HyeR7bkTeYZJntqQLA9ST4HOQ=
github.com/renstrom/shortuuid v3.0.0+incompatible/go.mod h1:n18Ycpn8DijG+h/lLBQVnGKv1BCtTeXo8KKSbBOrQ8c=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.0 h1:jlIyCplCJFULU/01vCkhKuTyc3OorI3bJFuw6obfgho=
github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/thoj/go-ircevent v0.0.0-20180816043103-14f3614f28c3 h1:389FrrKIAlxqQMTscCQ7VH3JAVuxb/pe53v2LBiA7z8=
github.com/thoj/go-ircevent v0.0.0-20180816043103-14f3614f28c3/go.mod h1:QYOctLs5qEsaIrA/PKEc4YqAv2SozbxNEX0vMPs84p4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

File diff suppressed because it is too large Load Diff

View File

@@ -51,7 +51,7 @@ func (channel *Channel) Names(client *Client) {
} }
func (channel *Channel) ClientIsOperator(client *Client) bool { func (channel *Channel) ClientIsOperator(client *Client) bool {
return client.flags[Operator] || channel.members.HasMode(client, ChannelOperator) return client.modes.Has(Operator) || channel.members.HasMode(client, ChannelOperator)
} }
func (channel *Channel) Nicks(target *Client) []string { func (channel *Channel) Nicks(target *Client) []string {
@@ -96,7 +96,7 @@ func (channel *Channel) String() string {
// <mode> <mode params> // <mode> <mode params>
func (channel *Channel) ModeString(client *Client) (str string) { func (channel *Channel) ModeString(client *Client) (str string) {
isMember := client.flags[Operator] || channel.members.Has(client) isMember := client.modes.Has(Operator) || channel.members.Has(client)
showKey := isMember && (channel.key != "") showKey := isMember && (channel.key != "")
showUserLimit := channel.userLimit > 0 showUserLimit := channel.userLimit > 0
@@ -244,7 +244,7 @@ func (channel *Channel) CanSpeak(client *Client) bool {
channel.members.HasMode(client, ChannelOperator)) { channel.members.HasMode(client, ChannelOperator)) {
return false return false
} }
if channel.flags.Has(SecureChan) && !client.flags[SecureConn] { if channel.flags.Has(SecureChan) && !client.modes.Has(SecureConn) {
return false return false
} }
return true return true
@@ -374,7 +374,7 @@ func (channel *Channel) applyMode(client *Client, change *ChannelModeChange) boo
return channel.applyModeMask(client, change.mode, change.op, return channel.applyModeMask(client, change.mode, change.op,
NewName(change.arg)) NewName(change.arg))
case InviteOnly, Moderated, NoOutside, OpOnlyTopic, Private, SecureChan: case InviteOnly, Moderated, NoOutside, OpOnlyTopic, Private, Secret, SecureChan:
return channel.applyModeFlag(client, change.mode, change.op) return channel.applyModeFlag(client, change.mode, change.op)
case Key: case Key:
@@ -513,7 +513,7 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client) {
inviter.RplInviting(invitee, channel.name) inviter.RplInviting(invitee, channel.name)
invitee.Reply(RplInviteMsg(inviter, invitee, channel.name)) invitee.Reply(RplInviteMsg(inviter, invitee, channel.name))
if invitee.flags[Away] { if invitee.modes.Has(Away) {
inviter.RplAway(invitee) inviter.RplAway(invitee)
} }
} }

View File

@@ -4,6 +4,7 @@ import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"net" "net"
"sync"
"time" "time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -14,6 +15,30 @@ const (
QUIT_TIMEOUT = time.Minute // how long after idle before a client is kicked QUIT_TIMEOUT = time.Minute // how long after idle before a client is kicked
) )
type SyncBool struct {
sync.RWMutex
value bool
}
func NewSyncBool(value bool) *SyncBool {
return &SyncBool{value: value}
}
func (sb *SyncBool) Get() bool {
sb.RLock()
defer sb.RUnlock()
return sb.value
}
func (sb *SyncBool) Set(value bool) {
sb.Lock()
defer sb.Unlock()
sb.value = value
}
type Client struct { type Client struct {
atime time.Time atime time.Time
authorized bool authorized bool
@@ -22,8 +47,8 @@ type Client struct {
capState CapState capState CapState
channels *ChannelSet channels *ChannelSet
ctime time.Time ctime time.Time
flags map[UserMode]bool modes *UserModeSet
hasQuit bool hasQuit *SyncBool
hops uint hops uint
hostname Name hostname Name
hostmask Name // Cloacked hostname (SHA256) hostmask Name // Cloacked hostname (SHA256)
@@ -42,14 +67,15 @@ type Client struct {
func NewClient(server *Server, conn net.Conn) *Client { func NewClient(server *Server, conn net.Conn) *Client {
now := time.Now() now := time.Now()
client := &Client{ c := &Client{
atime: now, atime: now,
authorized: len(server.password) == 0, authorized: len(server.password) == 0,
capState: CapNone, capState: CapNone,
capabilities: make(CapabilitySet), capabilities: make(CapabilitySet),
channels: NewChannelSet(), channels: NewChannelSet(),
ctime: now, ctime: now,
flags: make(map[UserMode]bool), modes: NewUserModeSet(),
hasQuit: NewSyncBool(false),
sasl: NewSaslState(), sasl: NewSaslState(),
server: server, server: server,
socket: NewSocket(conn), socket: NewSocket(conn),
@@ -57,45 +83,50 @@ func NewClient(server *Server, conn net.Conn) *Client {
} }
if _, ok := conn.(*tls.Conn); ok { if _, ok := conn.(*tls.Conn); ok {
client.flags[SecureConn] = true c.modes.Set(SecureConn)
} }
client.Touch() c.Touch()
go client.writeloop() go c.writeloop()
go client.readloop() go c.readloop()
return client return c
} }
// //
// command goroutine // command goroutine
// //
func (client *Client) writeloop() { func (c *Client) writeloop() {
for reply := range client.replies { for {
client.socket.Write(reply) select {
case reply, ok := <-c.replies:
if !ok || reply == "" || c.socket == nil {
return
}
c.socket.Write(reply)
}
} }
} }
func (client *Client) readloop() { func (c *Client) readloop() {
var command Command var command Command
var err error var err error
var line string var line string
// Set the hostname for this client. // Set the hostname for this client.
client.hostname = AddrLookupHostname(client.socket.conn.RemoteAddr()) c.hostname = AddrLookupHostname(c.socket.conn.RemoteAddr())
client.hostmask = NewName(SHA256(client.hostname.String())) c.hostmask = NewName(SHA256(c.hostname.String()))
for err == nil { for err == nil {
if line, err = client.socket.Read(); err != nil { if line, err = c.socket.Read(); err != nil {
command = NewQuitCommand("connection closed") command = NewQuitCommand("connection closed")
} else if command, err = ParseCommand(line); err != nil { } else if command, err = ParseCommand(line); err != nil {
switch err { switch err {
case ErrParseCommand: case ErrParseCommand:
//TODO(dan): use the real failed numeric for this (400) //TODO(dan): use the real failed numeric for this (400)
client.Reply(RplNotice(client.server, client, c.Reply(RplNotice(c.server, c, NewText("failed to parse command")))
NewText("failed to parse command")))
case NotEnoughArgsError: case NotEnoughArgsError:
// TODO // TODO
@@ -105,7 +136,7 @@ func (client *Client) readloop() {
continue continue
} else if checkPass, ok := command.(checkPasswordCommand); ok { } else if checkPass, ok := command.(checkPasswordCommand); ok {
checkPass.LoadPassword(client.server) checkPass.LoadPassword(c.server)
// Block the client thread while handling a potentially expensive // Block the client thread while handling a potentially expensive
// password bcrypt operation. Since the server is single-threaded // password bcrypt operation. Since the server is single-threaded
// for commands, we don't want the server to perform the bcrypt, // for commands, we don't want the server to perform the bcrypt,
@@ -114,182 +145,182 @@ func (client *Client) readloop() {
checkPass.CheckPassword() checkPass.CheckPassword()
} }
client.processCommand(command) c.processCommand(command)
} }
} }
func (client *Client) processCommand(cmd Command) { func (c *Client) processCommand(cmd Command) {
client.server.metrics.Counter("client", "commands").Inc() cmd.SetClient(c)
defer func(t time.Time) { if !c.registered {
v := client.server.metrics.SummaryVec("client", "command_duration_seconds")
v.WithLabelValues(cmd.Code().String()).Observe(time.Now().Sub(t).Seconds())
}(time.Now())
cmd.SetClient(client)
if !client.registered {
regCmd, ok := cmd.(RegServerCommand) regCmd, ok := cmd.(RegServerCommand)
if !ok { if !ok {
client.Quit("unexpected command") c.Quit("unexpected command")
return return
} }
regCmd.HandleRegServer(client.server) regCmd.HandleRegServer(c.server)
return return
} }
srvCmd, ok := cmd.(ServerCommand) srvCmd, ok := cmd.(ServerCommand)
if !ok { if !ok {
client.ErrUnknownCommand(cmd.Code()) c.ErrUnknownCommand(cmd.Code())
return return
} }
c.server.metrics.Counter("client", "commands").Inc()
defer func(t time.Time) {
v := c.server.metrics.SummaryVec("client", "command_duration_seconds")
v.WithLabelValues(cmd.Code().String()).Observe(time.Now().Sub(t).Seconds())
}(time.Now())
switch srvCmd.(type) { switch srvCmd.(type) {
case *PingCommand, *PongCommand: case *PingCommand, *PongCommand:
client.Touch() c.Touch()
case *QuitCommand: case *QuitCommand:
// no-op // no-op
default: default:
client.Active() c.Active()
client.Touch() c.Touch()
} }
srvCmd.HandleServer(client.server) srvCmd.HandleServer(c.server)
} }
// quit timer goroutine // quit timer goroutine
func (client *Client) connectionTimeout() { func (c *Client) connectionTimeout() {
client.processCommand(NewQuitCommand("connection timeout")) c.processCommand(NewQuitCommand("connection timeout"))
} }
// //
// idle timer goroutine // idle timer goroutine
// //
func (client *Client) connectionIdle() { func (c *Client) connectionIdle() {
client.server.idle <- client c.server.idle <- c
} }
// //
// server goroutine // server goroutine
// //
func (client *Client) Active() { func (c *Client) Active() {
client.atime = time.Now() c.atime = time.Now()
} }
func (client *Client) Touch() { func (c *Client) Touch() {
if client.quitTimer != nil { if c.quitTimer != nil {
client.quitTimer.Stop() c.quitTimer.Stop()
} }
if client.idleTimer == nil { if c.idleTimer == nil {
client.idleTimer = time.AfterFunc(IDLE_TIMEOUT, client.connectionIdle) c.idleTimer = time.AfterFunc(IDLE_TIMEOUT, c.connectionIdle)
} else { } else {
client.idleTimer.Reset(IDLE_TIMEOUT) c.idleTimer.Reset(IDLE_TIMEOUT)
} }
} }
func (client *Client) Idle() { func (c *Client) Idle() {
client.pingTime = time.Now() c.pingTime = time.Now()
client.Reply(RplPing(client.server)) c.Reply(RplPing(c.server))
if client.quitTimer == nil { if c.quitTimer == nil {
client.quitTimer = time.AfterFunc(QUIT_TIMEOUT, client.connectionTimeout) c.quitTimer = time.AfterFunc(QUIT_TIMEOUT, c.connectionTimeout)
} else { } else {
client.quitTimer.Reset(QUIT_TIMEOUT) c.quitTimer.Reset(QUIT_TIMEOUT)
} }
} }
func (client *Client) Register() { func (c *Client) Register() {
if client.registered { if c.registered {
return return
} }
client.registered = true c.registered = true
client.Touch() c.modes.Set(HostMask)
c.Touch()
} }
func (client *Client) destroy() { func (c *Client) destroy() {
// clean up channels // clean up channels
client.channels.Range(func(channel *Channel) bool { c.channels.Range(func(channel *Channel) bool {
channel.Quit(client) channel.Quit(c)
return true return true
}) })
// clean up server // clean up server
client.server.connections.Dec() if _, ok := c.socket.conn.(*tls.Conn); ok {
client.server.clients.Remove(client) c.server.metrics.GaugeVec("server", "clients").WithLabelValues("secure").Dec()
} else {
c.server.metrics.GaugeVec("server", "clients").WithLabelValues("insecure").Dec()
}
c.server.connections.Dec()
c.server.clients.Remove(c)
// clean up self // clean up self
if client.idleTimer != nil { if c.idleTimer != nil {
client.idleTimer.Stop() c.idleTimer.Stop()
} }
if client.quitTimer != nil { if c.quitTimer != nil {
client.quitTimer.Stop() c.quitTimer.Stop()
} }
close(client.replies) close(c.replies)
client.socket.Close() c.socket.Close()
log.Debugf("%s: destroyed", client) log.Debugf("%s: destroyed", c)
} }
func (client *Client) IdleTime() time.Duration { func (c *Client) IdleTime() time.Duration {
return time.Since(client.atime) return time.Since(c.atime)
} }
func (client *Client) SignonTime() int64 { func (c *Client) SignonTime() int64 {
return client.ctime.Unix() return c.ctime.Unix()
} }
func (client *Client) IdleSeconds() uint64 { func (c *Client) IdleSeconds() uint64 {
return uint64(client.IdleTime().Seconds()) return uint64(c.IdleTime().Seconds())
} }
func (client *Client) HasNick() bool { func (c *Client) HasNick() bool {
return client.nick != "" return c.nick != ""
} }
func (client *Client) HasUsername() bool { func (c *Client) HasUsername() bool {
return client.username != "" return c.username != ""
} }
func (client *Client) CanSpeak(target *Client) bool { func (c *Client) CanSpeak(target *Client) bool {
requiresSecure := client.flags[SecureOnly] || target.flags[SecureOnly] requiresSecure := c.modes.Has(SecureOnly) || target.modes.Has(SecureOnly)
isSecure := client.flags[SecureConn] && target.flags[SecureConn] isSecure := c.modes.Has(SecureConn) && target.modes.Has(SecureConn)
isOperator := client.flags[Operator] isOperator := c.modes.Has(Operator)
return !requiresSecure || (requiresSecure && (isOperator || isSecure)) return !requiresSecure || (requiresSecure && (isOperator || isSecure))
} }
// <mode> // <mode>
func (c *Client) ModeString() (str string) { func (c *Client) ModeString() (str string) {
for flag := range c.flags { return c.modes.String()
str += flag.String()
}
if len(str) > 0 {
str = "+" + str
}
return
} }
func (c *Client) UserHost(cloacked bool) Name { func (c *Client) UserHost(cloacked bool) Name {
username := "*" username := "*"
if c.HasUsername() { if c.username != "" {
username = c.username.String() username = c.username.String()
} }
if cloacked { if cloacked {
return Name(fmt.Sprintf("%s!%s@%s", c.Nick(), username, c.hostmask)) return Name(fmt.Sprintf("%s!%s@%s", c.nick, username, c.hostmask))
} }
return Name(fmt.Sprintf("%s!%s@%s", c.Nick(), username, c.hostname)) return Name(fmt.Sprintf("%s!%s@%s", c.nick, username, c.hostname))
} }
func (c *Client) Server() Name { func (c *Client) Server() Name {
@@ -315,10 +346,10 @@ func (c *Client) String() string {
return c.Id().String() return c.Id().String()
} }
func (client *Client) Friends() *ClientSet { func (c *Client) Friends() *ClientSet {
friends := NewClientSet() friends := NewClientSet()
friends.Add(client) friends.Add(c)
client.channels.Range(func(channel *Channel) bool { c.channels.Range(func(channel *Channel) bool {
channel.members.Range(func(member *Client, _ *ChannelModeSet) bool { channel.members.Range(func(member *Client, _ *ChannelModeSet) bool {
friends.Add(member) friends.Add(member)
return true return true
@@ -328,46 +359,48 @@ func (client *Client) Friends() *ClientSet {
return friends return friends
} }
func (client *Client) SetNickname(nickname Name) { func (c *Client) SetNickname(nickname Name) {
if client.HasNick() { if c.nick != "" {
log.Errorf("%s nickname already set!", client) log.Errorf("%s nickname already set!", c)
return return
} }
client.nick = nickname c.nick = nickname
client.server.clients.Add(client) c.server.clients.Add(c)
} }
func (client *Client) ChangeNickname(nickname Name) { func (c *Client) ChangeNickname(nickname Name) {
// Make reply before changing nick to capture original source id. // Make reply before changing nick to capture original source id.
reply := RplNick(client, nickname) reply := RplNick(c, nickname)
client.server.clients.Remove(client) c.server.clients.Remove(c)
client.server.whoWas.Append(client) c.server.whoWas.Append(c)
client.nick = nickname c.nick = nickname
client.server.clients.Add(client) c.server.clients.Add(c)
client.Friends().Range(func(friend *Client) bool { c.Friends().Range(func(friend *Client) bool {
friend.Reply(reply) friend.Reply(reply)
return true return true
}) })
} }
func (client *Client) Reply(reply string) { func (c *Client) Reply(reply string) {
client.replies <- reply if !c.hasQuit.Get() {
c.replies <- reply
}
} }
func (client *Client) Quit(message Text) { func (c *Client) Quit(message Text) {
if client.hasQuit { if c.hasQuit.Get() {
return return
} }
client.hasQuit = true c.hasQuit.Set(true)
client.Reply(RplError("quit")) c.Reply(RplError("quit"))
client.server.whoWas.Append(client) c.server.whoWas.Append(c)
friends := client.Friends() friends := c.Friends()
friends.Remove(client) friends.Remove(c)
client.destroy() c.destroy()
if friends.Count() > 0 { if friends.Count() > 0 {
reply := RplQuit(client, message) reply := RplQuit(c, message)
friends.Range(func(friend *Client) bool { friends.Range(func(friend *Client) bool {
friend.Reply(reply) friend.Reply(reply)
return true return true

View File

@@ -4,9 +4,7 @@ import (
"errors" "errors"
"regexp" "regexp"
"strings" "strings"
//"sync" "sync"
sync "github.com/sasha-s/go-deadlock"
"github.com/DanielOaks/girc-go/ircmatch" "github.com/DanielOaks/girc-go/ircmatch"
) )

View File

@@ -4,9 +4,7 @@ import (
"errors" "errors"
"io/ioutil" "io/ioutil"
"log" "log"
//"sync" "sync"
sync "github.com/sasha-s/go-deadlock"
"github.com/imdario/mergo" "github.com/imdario/mergo"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"

View File

@@ -3,6 +3,7 @@ package irc
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"sync"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -10,6 +11,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
// DefObjectives ...
var DefObjectives = map[float64]float64{ var DefObjectives = map[float64]float64{
0.50: 0.05, 0.50: 0.05,
0.90: 0.01, 0.90: 0.01,
@@ -17,20 +19,27 @@ var DefObjectives = map[float64]float64{
0.99: 0.001, 0.99: 0.001,
} }
// Metrics ...
type Metrics struct { type Metrics struct {
sync.RWMutex
namespace string namespace string
metrics map[string]prometheus.Metric metrics map[string]prometheus.Metric
guagevecs map[string]*prometheus.GaugeVec
sumvecs map[string]*prometheus.SummaryVec sumvecs map[string]*prometheus.SummaryVec
} }
// NewMetrics ...
func NewMetrics(namespace string) *Metrics { func NewMetrics(namespace string) *Metrics {
return &Metrics{ return &Metrics{
namespace: namespace, namespace: namespace,
metrics: make(map[string]prometheus.Metric), metrics: make(map[string]prometheus.Metric),
guagevecs: make(map[string]*prometheus.GaugeVec),
sumvecs: make(map[string]*prometheus.SummaryVec), sumvecs: make(map[string]*prometheus.SummaryVec),
} }
} }
// NewCounter ...
func (m *Metrics) NewCounter(subsystem, name, help string) prometheus.Counter { func (m *Metrics) NewCounter(subsystem, name, help string) prometheus.Counter {
counter := prometheus.NewCounter( counter := prometheus.NewCounter(
prometheus.CounterOpts{ prometheus.CounterOpts{
@@ -42,12 +51,15 @@ func (m *Metrics) NewCounter(subsystem, name, help string) prometheus.Counter {
) )
key := fmt.Sprintf("%s_%s", subsystem, name) key := fmt.Sprintf("%s_%s", subsystem, name)
m.Lock()
m.metrics[key] = counter m.metrics[key] = counter
m.Unlock()
prometheus.MustRegister(counter) prometheus.MustRegister(counter)
return counter return counter
} }
// NewCounterFunc ...
func (m *Metrics) NewCounterFunc(subsystem, name, help string, f func() float64) prometheus.CounterFunc { func (m *Metrics) NewCounterFunc(subsystem, name, help string, f func() float64) prometheus.CounterFunc {
counter := prometheus.NewCounterFunc( counter := prometheus.NewCounterFunc(
prometheus.CounterOpts{ prometheus.CounterOpts{
@@ -60,12 +72,15 @@ func (m *Metrics) NewCounterFunc(subsystem, name, help string, f func() float64)
) )
key := fmt.Sprintf("%s_%s", subsystem, name) key := fmt.Sprintf("%s_%s", subsystem, name)
m.Lock()
m.metrics[key] = counter m.metrics[key] = counter
m.Unlock()
prometheus.MustRegister(counter) prometheus.MustRegister(counter)
return counter return counter
} }
// NewGauge ...
func (m *Metrics) NewGauge(subsystem, name, help string) prometheus.Gauge { func (m *Metrics) NewGauge(subsystem, name, help string) prometheus.Gauge {
guage := prometheus.NewGauge( guage := prometheus.NewGauge(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
@@ -77,12 +92,15 @@ func (m *Metrics) NewGauge(subsystem, name, help string) prometheus.Gauge {
) )
key := fmt.Sprintf("%s_%s", subsystem, name) key := fmt.Sprintf("%s_%s", subsystem, name)
m.Lock()
m.metrics[key] = guage m.metrics[key] = guage
m.Unlock()
prometheus.MustRegister(guage) prometheus.MustRegister(guage)
return guage return guage
} }
// NewGaugeFunc ...
func (m *Metrics) NewGaugeFunc(subsystem, name, help string, f func() float64) prometheus.GaugeFunc { func (m *Metrics) NewGaugeFunc(subsystem, name, help string, f func() float64) prometheus.GaugeFunc {
guage := prometheus.NewGaugeFunc( guage := prometheus.NewGaugeFunc(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
@@ -95,12 +113,36 @@ func (m *Metrics) NewGaugeFunc(subsystem, name, help string, f func() float64) p
) )
key := fmt.Sprintf("%s_%s", subsystem, name) key := fmt.Sprintf("%s_%s", subsystem, name)
m.Lock()
m.metrics[key] = guage m.metrics[key] = guage
m.Unlock()
prometheus.MustRegister(guage) prometheus.MustRegister(guage)
return guage return guage
} }
// NewGaugeVec ...
func (m *Metrics) NewGaugeVec(subsystem, name, help string, labels []string) *prometheus.GaugeVec {
guagevec := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: m.namespace,
Subsystem: subsystem,
Name: name,
Help: help,
},
labels,
)
key := fmt.Sprintf("%s_%s", subsystem, name)
m.Lock()
m.guagevecs[key] = guagevec
m.Unlock()
prometheus.MustRegister(guagevec)
return guagevec
}
// NewSummary ...
func (m *Metrics) NewSummary(subsystem, name, help string) prometheus.Summary { func (m *Metrics) NewSummary(subsystem, name, help string) prometheus.Summary {
summary := prometheus.NewSummary( summary := prometheus.NewSummary(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
@@ -113,12 +155,15 @@ func (m *Metrics) NewSummary(subsystem, name, help string) prometheus.Summary {
) )
key := fmt.Sprintf("%s_%s", subsystem, name) key := fmt.Sprintf("%s_%s", subsystem, name)
m.Lock()
m.metrics[key] = summary m.metrics[key] = summary
m.Unlock()
prometheus.MustRegister(summary) prometheus.MustRegister(summary)
return summary return summary
} }
// NewSummaryVec ...
func (m *Metrics) NewSummaryVec(subsystem, name, help string, labels []string) *prometheus.SummaryVec { func (m *Metrics) NewSummaryVec(subsystem, name, help string, labels []string) *prometheus.SummaryVec {
sumvec := prometheus.NewSummaryVec( sumvec := prometheus.NewSummaryVec(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
@@ -132,36 +177,58 @@ func (m *Metrics) NewSummaryVec(subsystem, name, help string, labels []string) *
) )
key := fmt.Sprintf("%s_%s", subsystem, name) key := fmt.Sprintf("%s_%s", subsystem, name)
m.Lock()
m.sumvecs[key] = sumvec m.sumvecs[key] = sumvec
m.Unlock()
prometheus.MustRegister(sumvec) prometheus.MustRegister(sumvec)
return sumvec return sumvec
} }
// Counter ...
func (m *Metrics) Counter(subsystem, name string) prometheus.Counter { func (m *Metrics) Counter(subsystem, name string) prometheus.Counter {
key := fmt.Sprintf("%s_%s", subsystem, name) key := fmt.Sprintf("%s_%s", subsystem, name)
return m.metrics[key].(prometheus.Counter) return m.metrics[key].(prometheus.Counter)
} }
// Gauge ...
func (m *Metrics) Gauge(subsystem, name string) prometheus.Gauge { func (m *Metrics) Gauge(subsystem, name string) prometheus.Gauge {
key := fmt.Sprintf("%s_%s", subsystem, name) key := fmt.Sprintf("%s_%s", subsystem, name)
m.RLock()
defer m.RUnlock()
return m.metrics[key].(prometheus.Gauge) return m.metrics[key].(prometheus.Gauge)
} }
// GaugeVec ...
func (m *Metrics) GaugeVec(subsystem, name string) *prometheus.GaugeVec {
key := fmt.Sprintf("%s_%s", subsystem, name)
m.RLock()
defer m.RUnlock()
return m.guagevecs[key]
}
// Summary ...
func (m *Metrics) Summary(subsystem, name string) prometheus.Summary { func (m *Metrics) Summary(subsystem, name string) prometheus.Summary {
key := fmt.Sprintf("%s_%s", subsystem, name) key := fmt.Sprintf("%s_%s", subsystem, name)
m.RLock()
defer m.RUnlock()
return m.metrics[key].(prometheus.Summary) return m.metrics[key].(prometheus.Summary)
} }
// SummaryVec ...
func (m *Metrics) SummaryVec(subsystem, name string) *prometheus.SummaryVec { func (m *Metrics) SummaryVec(subsystem, name string) *prometheus.SummaryVec {
key := fmt.Sprintf("%s_%s", subsystem, name) key := fmt.Sprintf("%s_%s", subsystem, name)
m.RLock()
defer m.RUnlock()
return m.sumvecs[key] return m.sumvecs[key]
} }
// Handler ...
func (m *Metrics) Handler() http.Handler { func (m *Metrics) Handler() http.Handler {
return promhttp.Handler() return promhttp.Handler()
} }
// Run ...
func (m *Metrics) Run(addr string) { func (m *Metrics) Run(addr string) {
http.Handle("/", m.Handler()) http.Handle("/", m.Handler())
log.Infof("metrics endpoint listening on %s", addr) log.Infof("metrics endpoint listening on %s", addr)

51
irc/metrics_test.go Normal file
View File

@@ -0,0 +1,51 @@
package irc
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMetrics(t *testing.T) {
assert := assert.New(t)
m := NewMetrics("test")
m.NewCounter("foo", "counter", "help")
m.NewCounterFunc("foo", "counter_func", "help", func() float64 { return 1.0 })
m.NewGauge("foo", "gauge", "help")
m.NewGaugeFunc("foo", "gauge_func", "help", func() float64 { return 1.0 })
m.NewGaugeVec("foo", "gauge_vec", "help", []string{"test"})
m.Counter("foo", "counter").Inc()
m.Gauge("foo", "gauge").Add(1)
m.GaugeVec("foo", "gauge_vec").WithLabelValues("test").Add(1)
w := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/", nil)
m.Handler().ServeHTTP(w, r)
assert.Equal(w.Code, http.StatusOK)
assert.Regexp(
`
# HELP test_foo_counter help
# TYPE test_foo_counter counter
test_foo_counter 1
# HELP test_foo_counter_func help
# TYPE test_foo_counter_func counter
test_foo_counter_func 1
# HELP test_foo_gauge help
# TYPE test_foo_gauge gauge
test_foo_gauge 1
# HELP test_foo_gauge_func help
# TYPE test_foo_gauge_func gauge
test_foo_gauge_func 1
# HELP test_foo_gauge_vec help
# TYPE test_foo_gauge_vec gauge
test_foo_gauge_vec{test="test"} 1
`,
w.Body.String(),
)
}

View File

@@ -58,11 +58,12 @@ const (
Registered UserMode = 'r' // not a real user mode (flag) Registered UserMode = 'r' // not a real user mode (flag)
SecureConn UserMode = 'z' SecureConn UserMode = 'z'
SecureOnly UserMode = 'Z' SecureOnly UserMode = 'Z'
HostMask UserMode = 'x'
) )
var ( var (
SupportedUserModes = UserModes{ SupportedUserModes = UserModes{
Invisible, Operator, Invisible, Operator, HostMask,
} }
DefaultChannelModes = ChannelModes{ DefaultChannelModes = ChannelModes{
NoOutside, OpOnlyTopic, NoOutside, OpOnlyTopic,
@@ -70,7 +71,6 @@ var (
) )
const ( const (
Anonymous ChannelMode = 'a' // flag
BanMask ChannelMode = 'b' // arg BanMask ChannelMode = 'b' // arg
ChannelCreator ChannelMode = 'O' // flag ChannelCreator ChannelMode = 'O' // flag
ChannelOperator ChannelMode = 'o' // arg ChannelOperator ChannelMode = 'o' // arg
@@ -82,8 +82,6 @@ const (
NoOutside ChannelMode = 'n' // flag NoOutside ChannelMode = 'n' // flag
OpOnlyTopic ChannelMode = 't' // flag OpOnlyTopic ChannelMode = 't' // flag
Private ChannelMode = 'p' // flag Private ChannelMode = 'p' // flag
Quiet ChannelMode = 'q' // flag
ReOp ChannelMode = 'r' // flag
Secret ChannelMode = 's' // flag, deprecated Secret ChannelMode = 's' // flag, deprecated
UserLimit ChannelMode = 'l' // flag arg UserLimit ChannelMode = 'l' // flag arg
Voice ChannelMode = 'v' // arg Voice ChannelMode = 'v' // arg
@@ -93,7 +91,7 @@ const (
var ( var (
SupportedChannelModes = ChannelModes{ SupportedChannelModes = ChannelModes{
BanMask, ExceptMask, InviteMask, InviteOnly, Key, NoOutside, BanMask, ExceptMask, InviteMask, InviteOnly, Key, NoOutside,
OpOnlyTopic, Private, UserLimit, SecureChan, OpOnlyTopic, Private, UserLimit, Secret, SecureChan,
} }
) )
@@ -110,7 +108,7 @@ func (m *ModeCommand) HandleServer(s *Server) {
return return
} }
if client != target && !client.flags[Operator] { if client != target && !client.modes.Has(Operator) {
client.ErrUsersDontMatch() client.ErrUsersDontMatch()
return return
} }
@@ -119,29 +117,27 @@ func (m *ModeCommand) HandleServer(s *Server) {
for _, change := range m.changes { for _, change := range m.changes {
switch change.mode { switch change.mode {
case Invisible, WallOps, SecureOnly: case Invisible, HostMask, WallOps, SecureOnly:
switch change.op { switch change.op {
case Add: case Add:
if target.flags[change.mode] { if target.modes.Has(change.mode) {
continue continue
} }
target.flags[change.mode] = true target.modes.Set(change.mode)
changes = append(changes, change) changes = append(changes, change)
case Remove: case Remove:
if !target.flags[change.mode] { if !target.modes.Has(change.mode) {
continue continue
} }
delete(target.flags, change.mode) target.modes.Unset(change.mode)
changes = append(changes, change) changes = append(changes, change)
} }
case Operator: case Operator:
if change.op == Remove { if change.op == Remove {
if !target.flags[change.mode] { if !target.modes.Has(change.mode) {
continue continue
} }
delete(target.flags, change.mode) target.modes.Unset(change.mode)
changes = append(changes, change) changes = append(changes, change)
} }
} }

View File

@@ -67,7 +67,7 @@ type OperNickCommand struct {
func (msg *OperNickCommand) HandleServer(server *Server) { func (msg *OperNickCommand) HandleServer(server *Server) {
client := msg.Client() client := msg.Client()
if !client.flags[Operator] { if !client.modes.Has(Operator) {
client.ErrNoPrivileges() client.ErrNoPrivileges()
return return
} }

View File

@@ -4,9 +4,8 @@ import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
//"sync" "sync"
sync "github.com/sasha-s/go-deadlock"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

22
irc/privacy.go Normal file
View File

@@ -0,0 +1,22 @@
package irc
func CanSeeChannel(client *Client, channel *Channel) bool {
isPrivate := channel.flags.Has(Private)
isSecret := channel.flags.Has(Secret)
isMember := channel.members.Has(client)
isOperator := client.modes.Has(Operator)
isRegistered := client.modes.Has(Registered)
isSecure := client.modes.Has(SecureConn)
if !(isSecret || isPrivate) {
return true
}
if isSecret && (isMember || isOperator) {
return true
}
if isPrivate && (isMember || isOperator || (isRegistered && isSecure)) {
return true
}
return false
}

View File

@@ -249,24 +249,24 @@ func (target *Client) RplRehashing() {
func (target *Client) RplWhois(client *Client) { func (target *Client) RplWhois(client *Client) {
target.RplWhoisUser(client) target.RplWhoisUser(client)
if client.flags[Operator] { if client.modes.Has(Operator) {
target.RplWhoisOperator(client) target.RplWhoisOperator(client)
} }
target.RplWhoisIdle(client) target.RplWhoisIdle(client)
target.RplWhoisChannels(client) target.RplWhoisChannels(client)
if client.flags[SecureConn] { if client.modes.Has(SecureConn) {
target.RplWhoisSecure(client) target.RplWhoisSecure(client)
} }
target.RplWhoisServer(client) target.RplWhoisServer(client)
target.RplWhoisLoggedIn(client) target.RplWhoisLoggedIn(client)
target.RplEndOfWhois() target.RplEndOfWhois(client)
} }
func (target *Client) RplWhoisUser(client *Client) { func (target *Client) RplWhoisUser(client *Client) {
var clientHost Name var clientHost Name
if target.flags[Operator] { if target.modes.Has(Operator) || !client.modes.Has(HostMask) {
clientHost = client.hostname clientHost = client.hostname
} else { } else {
clientHost = client.hostmask clientHost = client.hostmask
@@ -324,9 +324,12 @@ func (target *Client) RplWhoisServer(client *Client) {
) )
} }
func (target *Client) RplEndOfWhois() { func (target *Client) RplEndOfWhois(client *Client) {
target.NumericReply(RPL_ENDOFWHOIS, target.NumericReply(
":End of WHOIS list") RPL_ENDOFWHOIS,
"%s :End of WHOIS list",
client.Nick(),
)
} }
func (target *Client) RplChannelModeIs(channel *Channel) { func (target *Client) RplChannelModeIs(channel *Channel) {
@@ -339,7 +342,7 @@ func (target *Client) RplChannelModeIs(channel *Channel) {
func (target *Client) RplWhoReply(channel *Channel, client *Client) { func (target *Client) RplWhoReply(channel *Channel, client *Client) {
var clientHost Name var clientHost Name
if target.flags[Operator] { if target.modes.Has(Operator) || !client.modes.Has(HostMask) {
clientHost = client.hostname clientHost = client.hostname
} else { } else {
clientHost = client.hostmask clientHost = client.hostmask
@@ -348,12 +351,12 @@ func (target *Client) RplWhoReply(channel *Channel, client *Client) {
channelName := "*" channelName := "*"
flags := "" flags := ""
if client.flags[Away] { if client.modes.Has(Away) {
flags = "G" flags = "G"
} else { } else {
flags = "H" flags = "H"
} }
if client.flags[Operator] { if client.modes.Has(Operator) {
flags += "*" flags += "*"
} }
@@ -486,8 +489,13 @@ func (target *Client) RplMOTDEnd() {
} }
func (target *Client) RplList(channel *Channel) { func (target *Client) RplList(channel *Channel) {
target.NumericReply(RPL_LIST, target.NumericReply(
"%s %d :%s", channel, channel.members.Count(), channel.topic) RPL_LIST,
"%s %d :%s",
channel,
channel.members.Count(),
channel.topic,
)
} }
func (target *Client) RplListEnd(server *Server) { func (target *Client) RplListEnd(server *Server) {
@@ -501,8 +509,12 @@ func (target *Client) RplNamReply(channel *Channel) {
} }
func (target *Client) RplWhoisChannels(client *Client) { func (target *Client) RplWhoisChannels(client *Client) {
target.MultilineReply(client.WhoisChannelsNames(), RPL_WHOISCHANNELS, target.MultilineReply(
"%s :%s", client.Nick()) client.WhoisChannelsNames(target),
RPL_WHOISCHANNELS,
"%s :%s",
client.Nick(),
)
} }
func (target *Client) RplVersion() { func (target *Client) RplVersion() {
@@ -567,7 +579,7 @@ func (target *Client) RplLUserChannels() {
func (target *Client) RplLUserOp() { func (target *Client) RplLUserOp() {
nOperators := 0 nOperators := 0
target.server.clients.Range(func(_ Name, client *Client) bool { target.server.clients.Range(func(_ Name, client *Client) bool {
if client.flags[Operator] { if client.modes.Has(Operator) {
nOperators++ nOperators++
} }
return true return true
@@ -598,7 +610,7 @@ func (target *Client) RplLUserMe() {
func (target *Client) RplWhoWasUser(whoWas *WhoWas) { func (target *Client) RplWhoWasUser(whoWas *WhoWas) {
var whoWasHost Name var whoWasHost Name
if target.flags[Operator] { if target.modes.Has(Operator) {
whoWasHost = whoWas.hostname whoWasHost = whoWas.hostname
} else { } else {
whoWasHost = whoWas.hostmask whoWasHost = whoWas.hostmask

View File

@@ -2,9 +2,7 @@ package irc
import ( import (
"bytes" "bytes"
//"sync" "sync"
sync "github.com/sasha-s/go-deadlock"
) )
type SaslState struct { type SaslState struct {

View File

@@ -44,13 +44,16 @@ type Server struct {
accounts PasswordStore accounts PasswordStore
password []byte password []byte
signals chan os.Signal signals chan os.Signal
done chan bool
whoWas *WhoWasList whoWas *WhoWasList
ids map[string]*Identity ids map[string]*Identity
} }
var ( var (
SERVER_SIGNALS = []os.Signal{syscall.SIGINT, syscall.SIGHUP, SERVER_SIGNALS = []os.Signal{
syscall.SIGTERM, syscall.SIGQUIT} syscall.SIGINT,
syscall.SIGTERM,
}
) )
func NewServer(config *Config) *Server { func NewServer(config *Config) *Server {
@@ -70,13 +73,14 @@ func NewServer(config *Config) *Server {
operators: config.Operators(), operators: config.Operators(),
accounts: NewMemoryPasswordStore(config.Accounts(), PasswordStoreOpts{}), accounts: NewMemoryPasswordStore(config.Accounts(), PasswordStoreOpts{}),
signals: make(chan os.Signal, len(SERVER_SIGNALS)), signals: make(chan os.Signal, len(SERVER_SIGNALS)),
done: make(chan bool),
whoWas: NewWhoWasList(100), whoWas: NewWhoWasList(100),
ids: make(map[string]*Identity), ids: make(map[string]*Identity),
} }
log.Debugf("accounts: %v", config.Accounts()) log.Debugf("accounts: %v", config.Accounts())
// TODO: Make this configurabel? // TODO: Make this configureable?
server.ids["global"] = NewIdentity(config.Server.Name, "global") server.ids["global"] = NewIdentity(config.Server.Name, "global")
if config.Server.Password != "" { if config.Server.Password != "" {
@@ -123,15 +127,22 @@ func NewServer(config *Config) *Server {
}, },
) )
// server clients gauge // server registered (clients) gauge
server.metrics.NewGaugeFunc( server.metrics.NewGaugeFunc(
"server", "clients", "server", "registered",
"Number of registered clients connected", "Number of registered clients connected",
func() float64 { func() float64 {
return float64(server.clients.Count()) return float64(server.clients.Count())
}, },
) )
// server clients gauge (by secure/insecure)
server.metrics.NewGaugeVec(
"server", "clients",
"Number of registered clients connected (by secure/insecure)",
[]string{"secure"},
)
// server channels gauge // server channels gauge
server.metrics.NewGaugeFunc( server.metrics.NewGaugeFunc(
"server", "channels", "server", "channels",
@@ -162,7 +173,7 @@ func NewServer(config *Config) *Server {
func (server *Server) Wallops(message string) { func (server *Server) Wallops(message string) {
text := NewText(message) text := NewText(message)
server.clients.Range(func(_ Name, client *Client) bool { server.clients.Range(func(_ Name, client *Client) bool {
if client.flags[WallOps] { if client.modes.Has(WallOps) {
server.metrics.Counter("client", "messages").Inc() server.metrics.Counter("client", "messages").Inc()
client.replies <- RplNotice(server, client, text) client.replies <- RplNotice(server, client, text)
} }
@@ -191,13 +202,22 @@ func (server *Server) Shutdown() {
server.Global("shutting down...") server.Global("shutting down...")
} }
func (server *Server) Stop() {
server.done <- true
}
func (server *Server) Run() { func (server *Server) Run() {
done := false for {
for !done {
select { select {
case <-server.done:
return
case <-server.signals: case <-server.signals:
server.Shutdown() server.Shutdown()
done = true // Give at least 1s for clients to see the shutdown
go func() {
time.Sleep(1 * time.Second)
server.Stop()
}()
case conn := <-server.newConns: case conn := <-server.newConns:
go NewClient(server, conn) go NewClient(server, conn)
@@ -217,6 +237,12 @@ func (s *Server) acceptor(listener net.Listener) {
} }
log.Debugf("%s accept: %s", s, conn.RemoteAddr()) log.Debugf("%s accept: %s", s, conn.RemoteAddr())
if _, ok := conn.(*tls.Conn); ok {
s.metrics.GaugeVec("server", "clients").WithLabelValues("secure").Inc()
} else {
s.metrics.GaugeVec("server", "clients").WithLabelValues("insecure").Inc()
}
s.connections.Inc() s.connections.Inc()
s.newConns <- conn s.newConns <- conn
} }
@@ -382,7 +408,7 @@ func (msg *RFC2812UserCommand) HandleRegServer(server *Server) {
flags := msg.Flags() flags := msg.Flags()
if len(flags) > 0 { if len(flags) > 0 {
for _, mode := range flags { for _, mode := range flags {
client.flags[mode] = true client.modes.Set(mode)
} }
client.RplUModeIs(client) client.RplUModeIs(client)
} }
@@ -469,7 +495,7 @@ func (msg *AuthenticateCommand) HandleRegServer(server *Server) {
client.RplLoggedIn(authcid) client.RplLoggedIn(authcid)
client.RplSaslSuccess() client.RplSaslSuccess()
client.flags[Registered] = true client.modes.Set(Registered)
client.Reply( client.Reply(
RplModeChanges( RplModeChanges(
client, client, client, client,
@@ -598,15 +624,19 @@ func (msg *PrivMsgCommand) HandleServer(server *Server) {
} }
server.metrics.Counter("client", "messages").Inc() server.metrics.Counter("client", "messages").Inc()
target.Reply(RplPrivMsg(client, target, msg.message)) target.Reply(RplPrivMsg(client, target, msg.message))
if target.flags[Away] { if target.modes.Has(Away) {
client.RplAway(target) client.RplAway(target)
} }
} }
func (client *Client) WhoisChannelsNames() []string { func (client *Client) WhoisChannelsNames(target *Client) []string {
chstrs := make([]string, client.channels.Count()) chstrs := make([]string, client.channels.Count())
index := 0 index := 0
client.channels.Range(func(channel *Channel) bool { client.channels.Range(func(channel *Channel) bool {
if !CanSeeChannel(target, channel) {
return true
}
switch { switch {
case channel.members.Get(client).Has(ChannelOperator): case channel.members.Get(client).Has(ChannelOperator):
chstrs[index] = "@" + channel.name.String() chstrs[index] = "@" + channel.name.String()
@@ -643,7 +673,7 @@ func (m *WhoisCommand) HandleServer(server *Server) {
func whoChannel(client *Client, channel *Channel, friends *ClientSet) { func whoChannel(client *Client, channel *Channel, friends *ClientSet) {
channel.members.Range(func(member *Client, _ *ChannelModeSet) bool { channel.members.Range(func(member *Client, _ *ChannelModeSet) bool {
if !client.flags[Invisible] || friends.Has(client) { if !client.modes.Has(Invisible) || friends.Has(client) {
client.RplWhoReply(channel, member) client.RplWhoReply(channel, member)
} }
return true return true
@@ -685,8 +715,8 @@ func (msg *OperCommand) HandleServer(server *Server) {
return return
} }
client.flags[Operator] = true client.modes.Set(Operator)
client.flags[WallOps] = true client.modes.Set(WallOps)
client.RplYoureOper() client.RplYoureOper()
client.Reply( client.Reply(
RplModeChanges( RplModeChanges(
@@ -701,7 +731,7 @@ func (msg *OperCommand) HandleServer(server *Server) {
func (msg *RehashCommand) HandleServer(server *Server) { func (msg *RehashCommand) HandleServer(server *Server) {
client := msg.Client() client := msg.Client()
if !client.flags[Operator] { if !client.modes.Has(Operator) {
client.ErrNoPrivileges() client.ErrNoPrivileges()
return return
} }
@@ -726,9 +756,9 @@ func (msg *RehashCommand) HandleServer(server *Server) {
func (msg *AwayCommand) HandleServer(server *Server) { func (msg *AwayCommand) HandleServer(server *Server) {
client := msg.Client() client := msg.Client()
if len(msg.text) > 0 { if len(msg.text) > 0 {
client.flags[Away] = true client.modes.Set(Away)
} else { } else {
delete(client.flags, Away) client.modes.Unset(Away)
} }
client.awayMessage = msg.text client.awayMessage = msg.text
} }
@@ -753,7 +783,7 @@ func (msg *MOTDCommand) HandleServer(server *Server) {
func (msg *NoticeCommand) HandleServer(server *Server) { func (msg *NoticeCommand) HandleServer(server *Server) {
client := msg.Client() client := msg.Client()
if msg.target == "*" && client.flags[Operator] { if msg.target == "*" && client.modes.Has(Operator) {
server.Global(msg.message.String()) server.Global(msg.message.String())
return return
} }
@@ -813,7 +843,7 @@ func (msg *ListCommand) HandleServer(server *Server) {
if len(msg.channels) == 0 { if len(msg.channels) == 0 {
server.channels.Range(func(name Name, channel *Channel) bool { server.channels.Range(func(name Name, channel *Channel) bool {
if !client.flags[Operator] && channel.flags.Has(Private) { if !CanSeeChannel(client, channel) {
return true return true
} }
client.RplList(channel) client.RplList(channel)
@@ -822,7 +852,7 @@ func (msg *ListCommand) HandleServer(server *Server) {
} else { } else {
for _, chname := range msg.channels { for _, chname := range msg.channels {
channel := server.channels.Get(chname) channel := server.channels.Get(chname)
if channel == nil || (!client.flags[Operator] && channel.flags.Has(Private)) { if channel == nil || !CanSeeChannel(client, channel) {
client.ErrNoSuchChannel(chname) client.ErrNoSuchChannel(chname)
continue continue
} }
@@ -902,7 +932,7 @@ func (msg *LUsersCommand) HandleServer(server *Server) {
func (msg *WallopsCommand) HandleServer(server *Server) { func (msg *WallopsCommand) HandleServer(server *Server) {
client := msg.Client() client := msg.Client()
if !client.flags[Operator] { if !client.modes.Has(Operator) {
client.ErrNoPrivileges() client.ErrNoPrivileges()
return return
} }
@@ -912,7 +942,7 @@ func (msg *WallopsCommand) HandleServer(server *Server) {
func (msg *KillCommand) HandleServer(server *Server) { func (msg *KillCommand) HandleServer(server *Server) {
client := msg.Client() client := msg.Client()
if !client.flags[Operator] { if !client.modes.Has(Operator) {
client.ErrNoPrivileges() client.ErrNoPrivileges()
return return
} }

View File

@@ -3,9 +3,7 @@ package irc
import ( import (
"fmt" "fmt"
"strings" "strings"
//"sync" "sync"
sync "github.com/sasha-s/go-deadlock"
) )
// //
@@ -96,6 +94,67 @@ func (c *ChannelNameMap) Remove(channel *Channel) error {
return nil return nil
} }
// UserModeSet holds a mapping of channel modes
type UserModeSet struct {
sync.RWMutex
modes map[UserMode]bool
}
// NewUserModeSet returns a new UserModeSet
func NewUserModeSet() *UserModeSet {
return &UserModeSet{modes: make(map[UserMode]bool)}
}
// Set sets mode
func (set *UserModeSet) Set(mode UserMode) {
set.Lock()
defer set.Unlock()
set.modes[mode] = true
}
// Unset unsets mode
func (set *UserModeSet) Unset(mode UserMode) {
set.Lock()
defer set.Unlock()
delete(set.modes, mode)
}
// Has returns true if the mode is set
func (set *UserModeSet) Has(mode UserMode) bool {
set.RLock()
defer set.RUnlock()
ok, _ := set.modes[mode]
return ok
}
// Range ranges of the modes calling f
func (set *UserModeSet) Range(f func(mode UserMode) bool) {
set.RLock()
defer set.RUnlock()
for mode := range set.modes {
if !f(mode) {
return
}
}
}
// String returns a string representing the channel modes
func (set *UserModeSet) String() string {
set.RLock()
defer set.RUnlock()
if len(set.modes) == 0 {
return ""
}
strs := make([]string, len(set.modes))
index := 0
for mode := range set.modes {
strs[index] = mode.String()
index++
}
return strings.Join(strs, "")
}
// ChannelModeSet holds a mapping of channel modes // ChannelModeSet holds a mapping of channel modes
type ChannelModeSet struct { type ChannelModeSet struct {
sync.RWMutex sync.RWMutex

View File

@@ -5,14 +5,11 @@ import (
) )
var ( var (
//PackageName package name // Package package name
Package = "eris" Package = "eris"
// Version release version // Version release version
Version = "1.6.2" Version = "1.6.4"
// Build will be overwritten automatically by the build system
Build = "dev"
// GitCommit will be overwritten automatically by the build system // GitCommit will be overwritten automatically by the build system
GitCommit = "HEAD" GitCommit = "HEAD"
@@ -20,5 +17,5 @@ var (
// FullVersion display the full version and build // FullVersion display the full version and build
func FullVersion() string { func FullVersion() string {
return fmt.Sprintf("%s-%s-%s@%s", Package, Version, Build, GitCommit) return fmt.Sprintf("%s-%s@%s", Package, Version, GitCommit)
} }

View File

@@ -1,9 +1,7 @@
package irc package irc
import ( import (
//"sync" "sync"
sync "github.com/sasha-s/go-deadlock"
) )
type WhoWasList struct { type WhoWasList struct {

View File

@@ -7,6 +7,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/mmcloughlin/professor"
"github.com/prologic/eris/irc" "github.com/prologic/eris/irc"
) )
@@ -33,6 +34,10 @@ func main() {
log.SetLevel(log.WarnLevel) log.SetLevel(log.WarnLevel)
} }
if debug {
go professor.Launch(":6060")
}
config, err := irc.LoadConfig(configfile) config, err := irc.LoadConfig(configfile)
if err != nil { if err != nil {
log.Fatal("Config file did not load successfully:", err.Error()) log.Fatal("Config file did not load successfully:", err.Error())

577
main_test.go Normal file
View File

@@ -0,0 +1,577 @@
package main
import (
"crypto/sha256"
"flag"
"fmt"
"os"
"strings"
"testing"
"time"
log "github.com/sirupsen/logrus"
"github.com/renstrom/shortuuid"
"github.com/stretchr/testify/assert"
"github.com/thoj/go-ircevent"
eris "github.com/prologic/eris/irc"
)
const (
TIMEOUT = 3 * time.Second
)
var (
server *eris.Server
debug = flag.Bool("d", false, "enable debug logging")
)
func setupServer() *eris.Server {
config := &eris.Config{}
config.Network.Name = "Test"
config.Server.Name = "test"
config.Server.Description = "Test"
config.Server.Listen = []string{":6667"}
// SASL
config.Account = map[string]*eris.PassConfig{
"admin": &eris.PassConfig{"JDJhJDA0JGtUU1JVc1JOUy9DbEh1WEdvYVlMdGVnclp6YnA3NDBOZGY1WUZhdTZtRzVmb1VKdXQ5ckZD"},
}
server := eris.NewServer(config)
go server.Run()
return server
}
func randomValidName() string {
var name eris.Name
for {
name = eris.NewName(shortuuid.New())
if name.IsNickname() {
break
}
}
return name.String()
}
func newClient(start bool) *irc.Connection {
name := randomValidName()
client := irc.IRC(name, name)
client.RealName = fmt.Sprintf("Test Client: %s", name)
err := client.Connect("localhost:6667")
if err != nil {
log.Fatalf("error setting up test client: %s", err)
}
if start {
go client.Loop()
}
return client
}
func TestMain(m *testing.M) {
flag.Parse()
if *debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.WarnLevel)
}
server = setupServer()
result := m.Run()
server.Stop()
os.Exit(result)
}
func TestConnection(t *testing.T) {
assert := assert.New(t)
expected := true
actual := make(chan bool)
client := newClient(false)
client.AddCallback("001", func(e *irc.Event) {
actual <- true
})
defer client.Quit()
go client.Loop()
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
func TestSASL(t *testing.T) {
assert := assert.New(t)
expected := true
actual := make(chan bool)
client := newClient(false)
client.SASLLogin = "admin"
client.SASLPassword = "admin"
client.AddCallback("001", func(e *irc.Event) {
actual <- true
})
defer client.Quit()
go client.Loop()
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
func TestRplWelcome(t *testing.T) {
assert := assert.New(t)
expected := "Welcome to the .* Internet Relay Network .*!.*@.*"
actual := make(chan string)
client := newClient(false)
client.AddCallback("001", func(e *irc.Event) {
actual <- e.Message()
})
defer client.Quit()
go client.Loop()
select {
case res := <-actual:
assert.Regexp(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
func TestUser_JOIN(t *testing.T) {
assert := assert.New(t)
client := newClient(false)
expected := []string{client.GetNick(), "=", "#join", fmt.Sprintf("@%s", client.GetNick())}
actual := make(chan string)
client.AddCallback("353", func(e *irc.Event) {
for i := range e.Arguments {
actual <- e.Arguments[i]
}
})
defer client.Quit()
go client.Loop()
client.Join("#join")
client.SendRaw("NAMES #join")
for i := range expected {
select {
case res := <-actual:
assert.Equal(expected[i], res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
}
func TestChannel_InviteOnly(t *testing.T) {
assert := assert.New(t)
expected := true
actual := make(chan bool)
client1 := newClient(false)
client2 := newClient(false)
client1.AddCallback("324", func(e *irc.Event) {
if strings.Contains(e.Arguments[2], "i") {
client2.Join("#inviteonly")
} else {
client1.Mode("#inviteonly")
}
})
client2.AddCallback("473", func(e *irc.Event) {
actual <- true
})
client2.AddCallback("JOIN", func(e *irc.Event) {
actual <- false
})
defer client1.Quit()
defer client2.Quit()
go client1.Loop()
go client2.Loop()
client1.Join("#inviteonly")
client1.Mode("#inviteonly", "+i")
client1.Mode("#inviteonly")
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
func TestUser_WithHostMask(t *testing.T) {
assert := assert.New(t)
client1 := newClient(false)
client2 := newClient(false)
expected := fmt.Sprintf("%x", sha256.Sum256([]byte("localhost")))
actual := make(chan string)
client1.AddCallback("001", func(e *irc.Event) {
client1.Mode(client1.GetNick(), "+x")
})
client2.AddCallback("001", func(e *irc.Event) {
client2.Whois(client1.GetNick())
})
client2.AddCallback("401", func(e *irc.Event) {
client2.Whois(client1.GetNick())
})
client2.AddCallback("311", func(e *irc.Event) {
actual <- e.Arguments[3]
})
defer client1.Quit()
defer client2.Quit()
go client1.Loop()
go client2.Loop()
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
/* FIXME: This test is racey :/
func TestUser_WithoutHostMask(t *testing.T) {
assert := assert.New(t)
client1 := newClient(false)
client2 := newClient(false)
expected := "localhost"
actual := make(chan string)
client1.AddCallback("001", func(e *irc.Event) {
client1.Mode(client1.GetNick(), "-x")
})
client2.AddCallback("001", func(e *irc.Event) {
client2.Whois(client1.GetNick())
})
client2.AddCallback("401", func(e *irc.Event) {
client2.Whois(client1.GetNick())
})
client2.AddCallback("311", func(e *irc.Event) {
actual <- e.Arguments[3]
})
defer client1.Quit()
defer client2.Quit()
go client1.Loop()
go client2.Loop()
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
*/
func TestUser_PRIVMSG(t *testing.T) {
assert := assert.New(t)
expected := "Hello World!"
actual := make(chan string)
client1 := newClient(false)
client2 := newClient(false)
client1.AddCallback("001", func(e *irc.Event) {
client1.Privmsg(client2.GetNick(), expected)
})
client1.AddCallback("PRIVMSG", func(e *irc.Event) {
actual <- e.Message()
})
client2.AddCallback("001", func(e *irc.Event) {
client2.Privmsg(client1.GetNick(), expected)
})
client2.AddCallback("PRIVMSG", func(e *irc.Event) {
actual <- e.Message()
})
defer client1.Quit()
defer client2.Quit()
go client1.Loop()
go client2.Loop()
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
func TestChannel_PRIVMSG(t *testing.T) {
assert := assert.New(t)
expected := "Hello World!"
actual := make(chan string)
client1 := newClient(false)
client2 := newClient(false)
client1.AddCallback("JOIN", func(e *irc.Event) {
client1.Privmsg(e.Arguments[0], expected)
})
client2.AddCallback("JOIN", func(e *irc.Event) {
client2.Privmsg(e.Arguments[0], expected)
})
client1.AddCallback("PRIVMSG", func(e *irc.Event) {
actual <- e.Message()
})
client2.AddCallback("PRIVMSG", func(e *irc.Event) {
actual <- e.Message()
})
defer client1.Quit()
defer client2.Quit()
go client1.Loop()
go client2.Loop()
client1.Join("#channelprivmsg")
client2.Join("#channelprivmsg")
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
func TestChannel_NoExternal(t *testing.T) {
assert := assert.New(t)
expected := true
actual := make(chan bool)
client1 := newClient(true)
client2 := newClient(true)
client1.AddCallback("JOIN", func(e *irc.Event) {
channel := e.Arguments[0]
if channel == "#noexternal" {
if e.Nick == client1.GetNick() {
client2.Privmsg("#noexternal", "FooBar!")
} else {
assert.Fail(fmt.Sprintf("unexpected user %s joined %s", e.Nick, channel))
}
} else {
assert.Fail(fmt.Sprintf("unexpected channel %s", channel))
}
})
client2.AddCallback("PRIVMSG", func(e *irc.Event) {
if e.Arguments[0] == "#noexternal" {
actual <- false
}
})
client2.AddCallback("404", func(e *irc.Event) {
actual <- true
})
defer client1.Quit()
defer client2.Quit()
go client1.Loop()
go client2.Loop()
client1.Join("#noexternal")
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
func TestChannel_SetTopic_InvalidChannel(t *testing.T) {
assert := assert.New(t)
expected := true
actual := make(chan bool)
client1 := newClient(false)
client1.AddCallback("403", func(e *irc.Event) {
actual <- true
})
defer client1.Quit()
go client1.Loop()
client1.SendRaw("TOPIC #invalidchannel :FooBar")
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
func TestChannel_SetTopic_NotOnChannel(t *testing.T) {
assert := assert.New(t)
expected := true
actual := make(chan bool)
client1 := newClient(false)
client2 := newClient(false)
client1.AddCallback("442", func(e *irc.Event) {
actual <- true
})
client2.AddCallback("JOIN", func(e *irc.Event) {
client1.SendRaw("TOPIC #notonchannel :FooBar")
})
defer client1.Quit()
go client1.Loop()
client2.Join("#notonchannel")
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
func TestChannel_BadChannelKey(t *testing.T) {
assert := assert.New(t)
expected := true
actual := make(chan bool)
client1 := newClient(false)
client2 := newClient(false)
client1.AddCallback("324", func(e *irc.Event) {
if strings.Contains(e.Arguments[2], "k") {
client2.Join(e.Arguments[1])
} else {
client1.Mode("#badchannelkey")
}
})
client2.AddCallback("JOIN", func(e *irc.Event) {
if e.Nick == client2.GetNick() && e.Arguments[0] == "#badchannelkey" {
actual <- false
}
})
client2.AddCallback("475", func(e *irc.Event) {
actual <- true
})
defer client1.Quit()
defer client2.Quit()
go client1.Loop()
go client2.Loop()
client1.Join("#badchannelkey")
client1.Mode("#badchannelkey", "+k", "opensesame")
client1.Mode("#badchannelkey")
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}
func TestChannel_GoodChannelKey(t *testing.T) {
assert := assert.New(t)
expected := true
actual := make(chan bool)
client1 := newClient(true)
client2 := newClient(true)
client1.AddCallback("324", func(e *irc.Event) {
if strings.Contains(e.Arguments[2], "k") {
client2.SendRawf("JOIN %s :opensesame", e.Arguments[1])
} else {
client1.Mode("#goodchannelkey")
}
})
client2.AddCallback("JOIN", func(e *irc.Event) {
if e.Nick == client2.GetNick() && e.Arguments[0] == "#goodchannelkey" {
actual <- true
}
})
client2.AddCallback("475", func(e *irc.Event) {
actual <- false
})
defer client1.Quit()
defer client2.Quit()
go client1.Loop()
go client2.Loop()
client1.Join("#goodchannelkey")
client1.Mode("#goodchannelkey", "+k", "opensesame")
client1.Mode("#goodchannelkey")
select {
case res := <-actual:
assert.Equal(expected, res)
case <-time.After(TIMEOUT):
assert.Fail("timeout")
}
}

1
vendor/github.com/beorn7/perks generated vendored

1
vendor/github.com/imdario/mergo generated vendored

1
vendor/golang.org/x/crypto generated vendored

Submodule vendor/golang.org/x/crypto deleted from b080dc9a8c

1
vendor/golang.org/x/sys generated vendored

Submodule vendor/golang.org/x/sys deleted from 4ff8c001ce

1
vendor/golang.org/x/text generated vendored

Submodule vendor/golang.org/x/text deleted from 88f656faf3

1
vendor/gopkg.in/yaml.v2 generated vendored

Submodule vendor/gopkg.in/yaml.v2 deleted from 287cf08546