ソースを参照

Split utils out to a separate subpackage

tags/v0.9.2-beta
Daniel Oaks 6年前
コミット
207c1074df
7個のファイルの変更20行の追加16行の削除
  1. 4
    3
      irc/client.go
  2. 2
    1
      irc/config.go
  3. 4
    3
      irc/monitor.go
  4. 5
    4
      irc/server.go
  5. 3
    3
      irc/utils/args.go
  6. 1
    1
      irc/utils/net.go
  7. 1
    1
      irc/utils/net_test.go

+ 4
- 3
irc/client.go ファイルの表示

@@ -21,6 +21,7 @@ import (
21 21
 	ident "github.com/oragono/go-ident"
22 22
 	"github.com/oragono/oragono/irc/caps"
23 23
 	"github.com/oragono/oragono/irc/sno"
24
+	"github.com/oragono/oragono/irc/utils"
24 25
 )
25 26
 
26 27
 const (
@@ -153,7 +154,7 @@ func (client *Client) IP() net.IP {
153 154
 		return net.ParseIP(client.proxiedIP)
154 155
 	}
155 156
 
156
-	return net.ParseIP(IPString(client.socket.conn.RemoteAddr()))
157
+	return net.ParseIP(utils.IPString(client.socket.conn.RemoteAddr()))
157 158
 }
158 159
 
159 160
 // IPString returns the IP address of this client as a string.
@@ -197,7 +198,7 @@ func (client *Client) run() {
197 198
 
198 199
 	// Set the hostname for this client
199 200
 	// (may be overridden by a later PROXY command from stunnel)
200
-	client.rawHostname = AddrLookupHostname(client.socket.conn.RemoteAddr())
201
+	client.rawHostname = utils.AddrLookupHostname(client.socket.conn.RemoteAddr())
201 202
 
202 203
 	for {
203 204
 		line, err = client.socket.Read()
@@ -451,7 +452,7 @@ func (client *Client) AllNickmasks() []string {
451 452
 		masks = append(masks, mask)
452 453
 	}
453 454
 
454
-	mask2, err := Casefold(fmt.Sprintf("%s!%s@%s", client.nick, client.username, IPString(client.socket.conn.RemoteAddr())))
455
+	mask2, err := Casefold(fmt.Sprintf("%s!%s@%s", client.nick, client.username, utils.IPString(client.socket.conn.RemoteAddr())))
455 456
 	if err == nil && mask2 != mask {
456 457
 		masks = append(masks, mask2)
457 458
 	}

+ 2
- 1
irc/config.go ファイルの表示

@@ -16,6 +16,7 @@ import (
16 16
 
17 17
 	"github.com/oragono/oragono/irc/custime"
18 18
 	"github.com/oragono/oragono/irc/logger"
19
+	"github.com/oragono/oragono/irc/utils"
19 20
 
20 21
 	"code.cloudfoundry.org/bytefmt"
21 22
 
@@ -383,7 +384,7 @@ func LoadConfig(filename string) (config *Config, err error) {
383 384
 	if config.Server.Name == "" {
384 385
 		return nil, errors.New("Server name missing")
385 386
 	}
386
-	if !IsHostname(config.Server.Name) {
387
+	if !utils.IsHostname(config.Server.Name) {
387 388
 		return nil, errors.New("Server name must match the format of a hostname")
388 389
 	}
389 390
 	if config.Datastore.Path == "" {

+ 4
- 3
irc/monitor.go ファイルの表示

@@ -10,6 +10,7 @@ import (
10 10
 	"sync"
11 11
 
12 12
 	"github.com/goshuirc/irc-go/ircmsg"
13
+	"github.com/oragono/oragono/irc/utils"
13 14
 )
14 15
 
15 16
 // MonitorManager keeps track of who's monitoring which nicks.
@@ -218,7 +219,7 @@ func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage) b
218 219
 		nickList = append(nickList, replynick)
219 220
 	}
220 221
 
221
-	for _, line := range argsToStrings(maxLastArgLength, nickList, ",") {
222
+	for _, line := range utils.ArgsToStrings(maxLastArgLength, nickList, ",") {
222 223
 		client.Send(nil, server.name, RPL_MONLIST, client.getNick(), line)
223 224
 	}
224 225
 
@@ -243,12 +244,12 @@ func monitorStatusHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
243 244
 	}
244 245
 
245 246
 	if len(online) > 0 {
246
-		for _, line := range argsToStrings(maxLastArgLength, online, ",") {
247
+		for _, line := range utils.ArgsToStrings(maxLastArgLength, online, ",") {
247 248
 			client.Send(nil, server.name, RPL_MONONLINE, client.getNick(), line)
248 249
 		}
249 250
 	}
250 251
 	if len(offline) > 0 {
251
-		for _, line := range argsToStrings(maxLastArgLength, offline, ",") {
252
+		for _, line := range utils.ArgsToStrings(maxLastArgLength, offline, ",") {
252 253
 			client.Send(nil, server.name, RPL_MONOFFLINE, client.getNick(), line)
253 254
 		}
254 255
 	}

+ 5
- 4
irc/server.go ファイルの表示

@@ -27,6 +27,7 @@ import (
27 27
 	"github.com/oragono/oragono/irc/isupport"
28 28
 	"github.com/oragono/oragono/irc/logger"
29 29
 	"github.com/oragono/oragono/irc/sno"
30
+	"github.com/oragono/oragono/irc/utils"
30 31
 	"github.com/tidwall/buntdb"
31 32
 )
32 33
 
@@ -267,7 +268,7 @@ func (server *Server) Run() {
267 268
 
268 269
 		case conn := <-server.newConns:
269 270
 			// check IP address
270
-			ipaddr := net.ParseIP(IPString(conn.Conn.RemoteAddr()))
271
+			ipaddr := net.ParseIP(utils.IPString(conn.Conn.RemoteAddr()))
271 272
 			if ipaddr == nil {
272 273
 				conn.Conn.Write([]byte(couldNotParseIPMsg))
273 274
 				conn.Conn.Close()
@@ -1034,7 +1035,7 @@ func (client *Client) getWhoisOf(target *Client) {
1034 1035
 		client.Send(nil, client.server.name, RPL_WHOISOPERATOR, client.nick, target.nick, target.whoisLine)
1035 1036
 	}
1036 1037
 	if client.flags[Operator] || client == target {
1037
-		client.Send(nil, client.server.name, RPL_WHOISACTUALLY, client.nick, target.nick, fmt.Sprintf("%s@%s", target.username, LookupHostname(target.IPString())), target.IPString(), "Actual user@host, Actual IP")
1038
+		client.Send(nil, client.server.name, RPL_WHOISACTUALLY, client.nick, target.nick, fmt.Sprintf("%s@%s", target.username, utils.LookupHostname(target.IPString())), target.IPString(), "Actual user@host, Actual IP")
1038 1039
 	}
1039 1040
 	if target.flags[TLS] {
1040 1041
 		client.Send(nil, client.server.name, RPL_WHOISSECURE, client.nick, target.nick, "is using a secure connection")
@@ -2177,7 +2178,7 @@ func proxyHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
2177 2178
 		return false
2178 2179
 	}
2179 2180
 
2180
-	clientAddress := IPString(client.socket.conn.RemoteAddr())
2181
+	clientAddress := utils.IPString(client.socket.conn.RemoteAddr())
2181 2182
 	clientHostname := client.hostname
2182 2183
 	for _, address := range server.proxyAllowedFrom {
2183 2184
 		if clientHostname == address || clientAddress == address {
@@ -2198,7 +2199,7 @@ func proxyHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
2198 2199
 
2199 2200
 			// override the client's regular IP
2200 2201
 			client.proxiedIP = msg.Params[1]
2201
-			client.rawHostname = LookupHostname(msg.Params[1])
2202
+			client.rawHostname = utils.LookupHostname(msg.Params[1])
2202 2203
 			client.hostname = client.rawHostname
2203 2204
 			return false
2204 2205
 		}

irc/util.go → irc/utils/args.go ファイルの表示

@@ -1,11 +1,11 @@
1 1
 // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
2 2
 // released under the MIT license
3 3
 
4
-package irc
4
+package utils
5 5
 
6
-// argsToStrings takes the arguments and splits them into a series of strings,
6
+// ArgsToStrings takes the arguments and splits them into a series of strings,
7 7
 // each argument separated by delim and each string bounded by maxLength.
8
-func argsToStrings(maxLength int, arguments []string, delim string) []string {
8
+func ArgsToStrings(maxLength int, arguments []string, delim string) []string {
9 9
 	var messages []string
10 10
 
11 11
 	var buffer string

irc/net.go → irc/utils/net.go ファイルの表示

@@ -2,7 +2,7 @@
2 2
 // Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
3 3
 // released under the MIT license
4 4
 
5
-package irc
5
+package utils
6 6
 
7 7
 import (
8 8
 	"net"

irc/net_test.go → irc/utils/net_test.go ファイルの表示

@@ -2,7 +2,7 @@
2 2
 // Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
3 3
 // released under the MIT license
4 4
 
5
-package irc
5
+package utils
6 6
 
7 7
 import "testing"
8 8
 

読み込み中…
キャンセル
保存