Compare commits
4 Commits
4fa84cc877
...
23f637dd47
Author | SHA1 | Date | |
---|---|---|---|
23f637dd47 | |||
4cd460886e | |||
4d8376fd3c | |||
01c3933a07 |
99
hid/main.go
99
hid/main.go
@ -87,7 +87,7 @@ func detectTLS(sysconn syscall.RawConn) (isTLS bool) {
|
|||||||
isTLS = buf[0]&0x80 != 0 && buf[2] == 1
|
isTLS = buf[0]&0x80 != 0 && buf[2] == 1
|
||||||
fallthrough
|
fallthrough
|
||||||
case n == 2:
|
case n == 2:
|
||||||
isTLS = buf[0] == 22 && buf[1] == 3
|
isTLS = isTLS || buf[0] == 22 && buf[1] == 3
|
||||||
case n == 1:
|
case n == 1:
|
||||||
isTLS = buf[0] == 22
|
isTLS = buf[0] == 22
|
||||||
case err == syscall.EAGAIN:
|
case err == syscall.EAGAIN:
|
||||||
@ -748,26 +748,29 @@ type writeEvent struct {
|
|||||||
err error // write error
|
err error // write error
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Port server_context. Maybe we want to keep it in a struct? A better
|
// TODO: Maybe we want to keep it in a struct?
|
||||||
// question might be: can we run multiple instances of it?
|
// A better question might be: can we run multiple instances of it?
|
||||||
|
var (
|
||||||
|
// network
|
||||||
|
|
||||||
|
listeners []net.Listener
|
||||||
|
clients = make(map[*client]bool)
|
||||||
|
|
||||||
|
// IRC state
|
||||||
|
|
||||||
// XXX: Beware that maps with identifier keys need to be indexed correctly.
|
// XXX: Beware that maps with identifier keys need to be indexed correctly.
|
||||||
// We might want to enforce accessor functions for users and channels.
|
// We might want to enforce accessor functions for users and channels.
|
||||||
var (
|
|
||||||
started time.Time // when has the server been started
|
|
||||||
|
|
||||||
|
started time.Time // when the server has been started
|
||||||
users = make(map[string]*client) // maps nicknames to clients
|
users = make(map[string]*client) // maps nicknames to clients
|
||||||
channels = make(map[string]*channel) // maps channel names to data
|
channels = make(map[string]*channel) // maps channel names to data
|
||||||
whowas = make(map[string]*whowasInfo) // WHOWAS registry
|
whowas = make(map[string]*whowasInfo) // WHOWAS registry
|
||||||
|
|
||||||
config simpleConfig // server configuration
|
// event loop
|
||||||
serverName string // our server name
|
|
||||||
pingInterval time.Duration // ping interval
|
quitting bool
|
||||||
maxConnections int // max connections allowed or 0
|
quitTimer <-chan time.Time
|
||||||
motd []string // MOTD (none if empty)
|
|
||||||
operators = make(map[string]bool) // TLS cert. fingerprints for IRCops
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
sigs = make(chan os.Signal, 1)
|
sigs = make(chan os.Signal, 1)
|
||||||
conns = make(chan net.Conn)
|
conns = make(chan net.Conn)
|
||||||
prepared = make(chan preparedEvent)
|
prepared = make(chan preparedEvent)
|
||||||
@ -775,11 +778,16 @@ var (
|
|||||||
writes = make(chan writeEvent)
|
writes = make(chan writeEvent)
|
||||||
timers = make(chan func())
|
timers = make(chan func())
|
||||||
|
|
||||||
tlsConf *tls.Config
|
// configuration
|
||||||
clients = make(map[*client]bool)
|
|
||||||
listeners []net.Listener
|
config simpleConfig // server configuration
|
||||||
quitting bool
|
tlsConf *tls.Config // TLS connection configuration
|
||||||
quitTimer <-chan time.Time
|
serverName string // our server name
|
||||||
|
pingInterval time.Duration // ping interval
|
||||||
|
maxConnections int // max connections allowed or 0
|
||||||
|
motd []string // MOTD (none if empty)
|
||||||
|
catalog map[int]string // message catalog for server msgs
|
||||||
|
operators map[string]bool // TLS certificate fingerprints for IRCops
|
||||||
)
|
)
|
||||||
|
|
||||||
// Forcefully tear down all connections.
|
// Forcefully tear down all connections.
|
||||||
@ -1073,11 +1081,14 @@ func (c *client) setPingTimer() {
|
|||||||
|
|
||||||
func (c *client) makeReply(id int, ap ...interface{}) string {
|
func (c *client) makeReply(id int, ap ...interface{}) string {
|
||||||
s := fmt.Sprintf(":%s %03d %s ", serverName, id, c.nicknameOrStar())
|
s := fmt.Sprintf(":%s %03d %s ", serverName, id, c.nicknameOrStar())
|
||||||
a := fmt.Sprintf(defaultReplies[id], ap...)
|
if reply, ok := catalog[id]; ok {
|
||||||
return s + a
|
return s + fmt.Sprintf(reply, ap...)
|
||||||
|
}
|
||||||
|
return s + fmt.Sprintf(defaultReplies[id], ap...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: This way we cannot typecheck the arguments, so we should be careful.
|
// XXX: This way simple static analysis cannot typecheck the arguments, so we
|
||||||
|
// need to be careful.
|
||||||
func (c *client) sendReply(id int, args ...interface{}) {
|
func (c *client) sendReply(id int, args ...interface{}) {
|
||||||
c.send(c.makeReply(id, args...))
|
c.send(c.makeReply(id, args...))
|
||||||
}
|
}
|
||||||
@ -3141,23 +3152,57 @@ func ircInitializeTLS() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ircInitializeCatalog() error {
|
func ircInitializeCatalog() error {
|
||||||
// TODO: Not going to use catgets but a simple text file with basic
|
configCatalog := config["catalog"]
|
||||||
// checking whether the index is used by this daemon at all should do.
|
if configCatalog == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path := resolveFilename(configCatalog, resolveRelativeConfigFilename)
|
||||||
|
if path == "" {
|
||||||
|
return fmt.Errorf("cannot find file: %s", configCatalog)
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed reading the MOTD file: %s", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
catalog = make(map[int]string)
|
||||||
|
for lineNo := 1; scanner.Scan(); lineNo++ {
|
||||||
|
line := strings.TrimLeft(scanner.Text(), " \t")
|
||||||
|
if line == "" || strings.HasPrefix(line, "#") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
delim := strings.IndexAny(line, " \t")
|
||||||
|
if delim < 0 {
|
||||||
|
return fmt.Errorf("%s:%d: malformed line", path, lineNo)
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := strconv.ParseUint(line[:delim], 10, 16)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%s:%d: %s", path, lineNo, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
catalog[int(id)] = line[delim+1:]
|
||||||
|
}
|
||||||
|
return scanner.Err()
|
||||||
|
}
|
||||||
|
|
||||||
func ircInitializeMOTD() error {
|
func ircInitializeMOTD() error {
|
||||||
configMOTD := config["motd"]
|
configMOTD := config["motd"]
|
||||||
if configMOTD == "" {
|
if configMOTD == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pathMOTD := resolveFilename(configMOTD, resolveRelativeConfigFilename)
|
path := resolveFilename(configMOTD, resolveRelativeConfigFilename)
|
||||||
if pathMOTD == "" {
|
if path == "" {
|
||||||
return fmt.Errorf("cannot find file: %s", configMOTD)
|
return fmt.Errorf("cannot find file: %s", configMOTD)
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Open(pathMOTD)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed reading the MOTD file: %s", err)
|
return fmt.Errorf("failed reading the MOTD file: %s", err)
|
||||||
}
|
}
|
||||||
@ -3281,7 +3326,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
if flag.NArg() > 0 {
|
if flag.NArg() > 0 {
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
os.Exit(1)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
config = make(simpleConfig)
|
config = make(simpleConfig)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user