Pārlūkot izejas kodu

Add comments

tags/v0.7.0
Daniel Oaks 7 gadus atpakaļ
vecāks
revīzija
1798572015
4 mainītis faili ar 27 papildinājumiem un 20 dzēšanām
  1. 6
    17
      irc/capability.go
  2. 14
    2
      irc/client_lookup_set.go
  3. 1
    1
      irc/message_tags.go
  4. 6
    0
      irc/numerics.go

+ 6
- 17
irc/capability.go Parādīt failu

@@ -10,7 +10,7 @@ import (
10 10
 	"github.com/DanielOaks/girc-go/ircmsg"
11 11
 )
12 12
 
13
-// Capabilities are optional features a client may request from a server.
13
+// Capability represents an optional feature that a client may request from the server.
14 14
 type Capability string
15 15
 
16 16
 const (
@@ -33,6 +33,7 @@ const (
33 33
 )
34 34
 
35 35
 var (
36
+	// SupportedCapabilities are the caps we advertise.
36 37
 	SupportedCapabilities = CapabilitySet{
37 38
 		AccountTag:    true,
38 39
 		AccountNotify: true,
@@ -51,6 +52,7 @@ var (
51 52
 		// STS is set during server startup
52 53
 		UserhostInNames: true,
53 54
 	}
55
+	// CapValues are the actual values we advertise to v3.2 clients.
54 56
 	CapValues = map[Capability]string{
55 57
 		SASL: "PLAIN,EXTERNAL",
56 58
 	}
@@ -60,20 +62,7 @@ func (capability Capability) String() string {
60 62
 	return string(capability)
61 63
 }
62 64
 
63
-// CapModifiers are indicators showing the state of a capability after a REQ or
64
-// ACK.
65
-type CapModifier rune
66
-
67
-const (
68
-	Ack     CapModifier = '~'
69
-	Disable CapModifier = '-'
70
-	Sticky  CapModifier = '='
71
-)
72
-
73
-func (mod CapModifier) String() string {
74
-	return string(mod)
75
-}
76
-
65
+// CapState shows whether we're negotiating caps, finished, etc for connection registration.
77 66
 type CapState uint
78 67
 
79 68
 const (
@@ -116,8 +105,8 @@ func (set CapabilitySet) DisableString() string {
116 105
 	parts := make([]string, len(set))
117 106
 	index := 0
118 107
 	for capability := range set {
119
-		parts[index] = Disable.String() + capability.String()
120
-		index += 1
108
+		parts[index] = "-" + capability.String()
109
+		index++
121 110
 	}
122 111
 	return strings.Join(parts, " ")
123 112
 }

+ 14
- 2
irc/client_lookup_set.go Parādīt failu

@@ -22,10 +22,11 @@ var (
22 22
 	ErrNicknameMismatch = errors.New("nickname mismatch")
23 23
 )
24 24
 
25
+// ExpandUserHost takes a userhost, and returns an expanded version.
25 26
 func ExpandUserHost(userhost string) (expanded string) {
26 27
 	expanded = userhost
27 28
 	// fill in missing wildcards for nicks
28
-	//TODO(dan): this would fail with dan@lol, do we want to accommodate that?
29
+	//TODO(dan): this would fail with dan@lol, fix that.
29 30
 	if !strings.Contains(expanded, "!") {
30 31
 		expanded += "!*"
31 32
 	}
@@ -35,17 +36,20 @@ func ExpandUserHost(userhost string) (expanded string) {
35 36
 	return
36 37
 }
37 38
 
39
+// ClientLookupSet represents a way to store, search and lookup clients.
38 40
 type ClientLookupSet struct {
39 41
 	ByNickMutex sync.RWMutex
40 42
 	ByNick      map[string]*Client
41 43
 }
42 44
 
45
+// NewClientLookupSet returns a new lookup set.
43 46
 func NewClientLookupSet() *ClientLookupSet {
44 47
 	return &ClientLookupSet{
45 48
 		ByNick: make(map[string]*Client),
46 49
 	}
47 50
 }
48 51
 
52
+// Count returns how many clients are in the lookup set.
49 53
 func (clients *ClientLookupSet) Count() int {
50 54
 	clients.ByNickMutex.RLock()
51 55
 	defer clients.ByNickMutex.RUnlock()
@@ -53,7 +57,8 @@ func (clients *ClientLookupSet) Count() int {
53 57
 	return count
54 58
 }
55 59
 
56
-//TODO(dan): wouldn't it be best to always use Get rather than this?
60
+// Has returns whether or not the given client exists.
61
+//TODO(dan): This seems like ripe ground for a race, if code does Has then Get, and assumes the Get will return a client.
57 62
 func (clients *ClientLookupSet) Has(nick string) bool {
58 63
 	casefoldedName, err := CasefoldName(nick)
59 64
 	if err == nil {
@@ -75,6 +80,7 @@ func (clients *ClientLookupSet) getNoMutex(nick string) *Client {
75 80
 	return nil
76 81
 }
77 82
 
83
+// Get retrieves a client from the set, if they exist.
78 84
 func (clients *ClientLookupSet) Get(nick string) *Client {
79 85
 	casefoldedName, err := CasefoldName(nick)
80 86
 	if err == nil {
@@ -86,6 +92,7 @@ func (clients *ClientLookupSet) Get(nick string) *Client {
86 92
 	return nil
87 93
 }
88 94
 
95
+// Add adds a client to the lookup set.
89 96
 func (clients *ClientLookupSet) Add(client *Client, nick string) error {
90 97
 	nick, err := CasefoldName(nick)
91 98
 	if err != nil {
@@ -100,6 +107,7 @@ func (clients *ClientLookupSet) Add(client *Client, nick string) error {
100 107
 	return nil
101 108
 }
102 109
 
110
+// Remove removes a client from the lookup set.
103 111
 func (clients *ClientLookupSet) Remove(client *Client) error {
104 112
 	if !client.HasNick() {
105 113
 		return ErrNickMissing
@@ -113,6 +121,7 @@ func (clients *ClientLookupSet) Remove(client *Client) error {
113 121
 	return nil
114 122
 }
115 123
 
124
+// Replace renames an existing client in the lookup set.
116 125
 func (clients *ClientLookupSet) Replace(oldNick, newNick string, client *Client) error {
117 126
 	// get casefolded nicknames
118 127
 	oldNick, err := CasefoldName(oldNick)
@@ -145,6 +154,7 @@ func (clients *ClientLookupSet) Replace(oldNick, newNick string, client *Client)
145 154
 	return nil
146 155
 }
147 156
 
157
+// AllWithCaps returns all clients with the given capabilities.
148 158
 func (clients *ClientLookupSet) AllWithCaps(caps ...Capability) (set ClientSet) {
149 159
 	set = make(ClientSet)
150 160
 
@@ -165,6 +175,7 @@ func (clients *ClientLookupSet) AllWithCaps(caps ...Capability) (set ClientSet)
165 175
 	return set
166 176
 }
167 177
 
178
+// FindAll returns all clients that match the given userhost mask.
168 179
 func (clients *ClientLookupSet) FindAll(userhost string) (set ClientSet) {
169 180
 	set = make(ClientSet)
170 181
 
@@ -185,6 +196,7 @@ func (clients *ClientLookupSet) FindAll(userhost string) (set ClientSet) {
185 196
 	return set
186 197
 }
187 198
 
199
+// Find returns the first client that matches the given userhost mask.
188 200
 func (clients *ClientLookupSet) Find(userhost string) *Client {
189 201
 	userhost, err := Casefold(ExpandUserHost(userhost))
190 202
 	if err != nil {

+ 1
- 1
irc/message_tags.go Parādīt failu

@@ -5,7 +5,7 @@ package irc
5 5
 
6 6
 import "github.com/DanielOaks/girc-go/ircmsg"
7 7
 
8
-// GetClientOnlyTags tags a tag map, and returns a map containing just the client-only tags from it.
8
+// GetClientOnlyTags takes a tag map and returns a map containing just the client-only tags from it.
9 9
 func GetClientOnlyTags(tags map[string]ircmsg.TagValue) *map[string]ircmsg.TagValue {
10 10
 	if len(tags) < 1 {
11 11
 		return nil

+ 6
- 0
irc/numerics.go Parādīt failu

@@ -5,6 +5,12 @@
5 5
 
6 6
 package irc
7 7
 
8
+// These numerics have been retrieved from:
9
+//   http://defs.ircdocs.horse/ and http://modern.ircdocs.horse/
10
+//
11
+// They're intended to represent a relatively-standard cross-section of the IRC
12
+// server ecosystem out there. Custom numerics will be marked as such.
13
+
8 14
 const (
9 15
 	RPL_WELCOME                     = "001"
10 16
 	RPL_YOURHOST                    = "002"

Notiek ielāde…
Atcelt
Saglabāt