1. murarth
  2. GoIRCd

Commits

murarth  committed 06f27a0

Update to Go weekly 2012-03-13

  • Participants
  • Parent commits a5fdc4d
  • Branches default

Comments (0)

Files changed (5)

File Makefile

-# Makefile
-
-include $(GOROOT)/src/Make.inc
-
-TARG = goircd-bin
-GOFILES = \
-	bind.go \
-	channel.go \
-	command.go \
-	config.go \
-	connect.go \
-	errors.go \
-	events.go \
-	fakelag.go \
-	goircd.go \
-	links.go \
-	localuser.go \
-	logger.go \
-	main.go \
-	misc.go \
-	modes.go \
-	modules.go \
-	oper.go \
-	password.go \
-	scommand.go \
-	server.go \
-	server_cmds.go \
-	user.go \
-	version.go \
-	wildcard.go \
-	xline.go \
-	$(wildcard commands/cmd_*.go) \
-	$(wildcard modes/?mode_*.go) \
-	$(wildcard modules/m_*.go) \
-
-CLEANFILES += version.go
-
-include $(GOROOT)/src/Make.cmd
-
-version.go: mkversion.sh
-	./mkversion.sh > $@

File goircd.go

View file
 	buf := make([]byte, bufSize)
 	off := 0
 
-	user.Connection.SetWriteTimeout(250000000)
+	writeTimeout := time.Duration(0.25e9)
 
 	for {
 		var newSize int
 				goto handleLine
 			}
 		} else {
+			deadline := time.Now()
+			deadline.Add(writeTimeout)
+
+			user.Connection.SetWriteDeadline(deadline)
+
 			// Otherwise, only poll the channels.
 			// Then, continue attempting to flush the queue.
 			n, err := user.Connection.Write(buf[:off])
 		handler.(ReadyHandler).Ready(self)
 	}
 
+	sigIncoming := make(chan os.Signal, 5)
+	signal.Notify(sigIncoming)
+
 	for {
 		select {
 		case cl := <-self.pendingClients:
 			self.HandleMessage(msg.User, msg.Tokens, msg.Error)
 		case msg := <-self.serverMessages:
 			self.HandleServerMessage(msg.Node, msg.Tokens, msg.Line, msg.Error)
-		case sig := <-signal.Incoming:
-			if unixSig, ok := sig.(os.UnixSignal); ok {
+		case sig := <-sigIncoming:
+			if unixSig, ok := sig.(syscall.Signal); ok {
 				switch unixSig {
 				case syscall.SIGHUP:
 					self.ServerNotice('a', "Received SIGHUP, rehashing...")
 	}
 
 	if self.doRestart {
-		if err := os.Exec(os.Args[0], os.Args, nil); err != nil {
+		if err := syscall.Exec(os.Args[0], os.Args, os.Environ()); err != nil {
 			self.Fatal("Failed to exec process: %s", err)
 		}
 	}
 			self.pendingClients <- user
 		} else {
 			// An EINVAL is likely from the Listener being closed
-			if err != os.EINVAL {
+			if err != syscall.EINVAL {
 				self.Log(Error, "Client listener encountered error: %s", err)
 			}
 			return
 			self.pendingServers <- node
 		} else {
 			// An EINVAL is likely from the Listener being closed
-			if err != os.EINVAL {
+			if err != syscall.EINVAL {
 				self.Log(Error, "Server listener encountered error: %s", err)
 			}
 			return

File localuser.go

View file
 	user.Type = UserLocal
 
 	// All reads and writes blocking
-	conn.SetTimeout(0)
 	addr := conn.RemoteAddr()
 
 	_, tls := conn.(*tls.Conn)

File modules/m_cloak.go

View file
 		ipstr := ip.String()
 		res += clk.cloakString(ipstr, 10, 6)
 		res += "."
-		ipstr = ipstr[8:]
-		res += clk.cloakString(ipstr, 11, 4)
+		if len(ipstr) > 8 {
+			res += clk.cloakString(ipstr[8:], 11, 6)
+		} else {
+			res += clk.cloakString(ipstr, 11, 6)
+		}
 		res += fmt.Sprintf(".%02x%02x.%02x%02x", ip[2], ip[3], ip[0], ip[1])
 	}
 

File server.go

View file
 import (
 	"bytes"
 	"crypto/hmac"
+	"crypto/sha256"
 	"crypto/tls"
 	"encoding/hex"
 	"fmt"
 }
 
 func HMACResponse(key, challenge string) string {
-	hmac256 := hmac.NewSHA256([]byte(key))
+	hmac256 := hmac.New(sha256.New, []byte(key))
 	hmac256.Write([]byte(challenge))
 
 	return "HMAC-SHA256:" + hex.EncodeToString(hmac256.Sum(nil))