mirror of
https://github.com/mochi-mqtt/server.git
synced 2025-10-30 03:01:58 +08:00
start establish
This commit is contained in:
@@ -178,7 +178,6 @@ func (s *Server) EstablishConnection(lid string, c net.Conn, ac auth.Controller)
|
||||
}
|
||||
|
||||
debug.Println(client.id, "^^ CLIENT READ ENDED, ENDING", err)
|
||||
//debug.Println(client.id, "FINAL BUF", string(client.r.Get()))
|
||||
|
||||
// Publish last will and testament then close.
|
||||
s.closeClient(client, sendLWT)
|
||||
|
||||
@@ -8,5 +8,5 @@ type Controller interface {
|
||||
Authenticate(user, password []byte) bool
|
||||
|
||||
// ACL returns true if a user has read or write access to a given topic.
|
||||
ACL(user string, topic string, write bool) bool
|
||||
ACL(user []byte, topic string, write bool) bool
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ func (a *Allow) Authenticate(user, password []byte) bool {
|
||||
|
||||
// ACL returns true if a user has access permissions to read or write on a topic.
|
||||
// Allow always returns true.
|
||||
func (a *Allow) ACL(user, topic string, write bool) bool {
|
||||
func (a *Allow) ACL(user []byte, topic string, write bool) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@ func (d *Disallow) Authenticate(user, password []byte) bool {
|
||||
|
||||
// ACL returns true if a user has access permissions to read or write on a topic.
|
||||
// Disallow always returns false.
|
||||
func (d *Disallow) ACL(user, topic string, write bool) bool {
|
||||
func (d *Disallow) ACL(user []byte, topic string, write bool) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -8,48 +8,48 @@ import (
|
||||
|
||||
func TestAllowAuth(t *testing.T) {
|
||||
ac := new(Allow)
|
||||
require.Equal(t, true, ac.Authenticate("user", "pass"))
|
||||
require.Equal(t, true, ac.Authenticate([]byte("user"), []byte("pass")))
|
||||
}
|
||||
|
||||
func BenchmarkAllowAuth(b *testing.B) {
|
||||
ac := new(Allow)
|
||||
for n := 0; n < b.N; n++ {
|
||||
ac.Authenticate("user", "pass")
|
||||
ac.Authenticate([]byte("user"), []byte("pass"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllowACL(t *testing.T) {
|
||||
ac := new(Allow)
|
||||
require.Equal(t, true, ac.ACL("user", "topic", true))
|
||||
require.Equal(t, true, ac.ACL([]byte("user"), "topic", true))
|
||||
}
|
||||
|
||||
func BenchmarkAllowACL(b *testing.B) {
|
||||
ac := new(Allow)
|
||||
for n := 0; n < b.N; n++ {
|
||||
ac.ACL("user", "pass", true)
|
||||
ac.ACL([]byte("user"), "pass", true)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisallowAuth(t *testing.T) {
|
||||
ac := new(Disallow)
|
||||
require.Equal(t, false, ac.Authenticate("user", "pass"))
|
||||
require.Equal(t, false, ac.Authenticate([]byte("user"), []byte("pass")))
|
||||
}
|
||||
|
||||
func BenchmarkDisallowAuth(b *testing.B) {
|
||||
ac := new(Disallow)
|
||||
for n := 0; n < b.N; n++ {
|
||||
ac.Authenticate("user", "pass")
|
||||
ac.Authenticate([]byte("user"), []byte("pass"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisallowACL(t *testing.T) {
|
||||
ac := new(Disallow)
|
||||
require.Equal(t, false, ac.ACL("user", "topic", true))
|
||||
require.Equal(t, false, ac.ACL([]byte("user"), "topic", true))
|
||||
}
|
||||
|
||||
func BenchmarkDisallowACL(b *testing.B) {
|
||||
ac := new(Disallow)
|
||||
for n := 0; n < b.N; n++ {
|
||||
ac.ACL("user", "pass", true)
|
||||
ac.ACL([]byte("user"), "pass", true)
|
||||
}
|
||||
}
|
||||
|
||||
8
mqtt.go
8
mqtt.go
@@ -1,7 +1,6 @@
|
||||
package mqtt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
@@ -150,7 +149,7 @@ func (s *Server) EstablishConnection(lid string, c net.Conn, ac auth.Controller)
|
||||
retcode = packets.CodeConnectNotAuthorised
|
||||
}
|
||||
|
||||
dbg.Printf("%s %+v\n", dbg.Bold+">> Connect Validated\n "+dbg.Reset, pk)
|
||||
dbg.Printf("%s %+v\n", dbg.Bold+">> Connect Validated"+dbg.Reset, pk)
|
||||
|
||||
var sessionPresent bool
|
||||
if existing, ok := s.Clients.Get(pk.ClientIdentifier); ok {
|
||||
@@ -172,7 +171,7 @@ func (s *Server) EstablishConnection(lid string, c net.Conn, ac auth.Controller)
|
||||
s.Clients.Add(client)
|
||||
|
||||
// Send a CONNACK back to the client.
|
||||
/*err = s.writeClient(client, &packets.ConnackPacket{
|
||||
err = s.writeClient(client, &packets.Packet{
|
||||
FixedHeader: packets.FixedHeader{
|
||||
Type: packets.Connack,
|
||||
},
|
||||
@@ -182,7 +181,6 @@ func (s *Server) EstablishConnection(lid string, c net.Conn, ac auth.Controller)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*/
|
||||
|
||||
if retcode != packets.Accepted {
|
||||
return nil
|
||||
@@ -211,7 +209,7 @@ func (s *Server) EstablishConnection(lid string, c net.Conn, ac auth.Controller)
|
||||
}
|
||||
|
||||
// writeClient writes packets to a client connection.
|
||||
func (s *Server) writeClient(cl *client, pk packets.Packet) error {
|
||||
func (s *Server) writeClient(cl *clients.Client, pk *packets.Packet) error {
|
||||
_, err := cl.WritePacket(pk)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user