start establish

This commit is contained in:
Mochi
2019-11-24 22:17:34 +00:00
parent 4ddfa37ea4
commit a33add6b0e
5 changed files with 14 additions and 17 deletions

View File

@@ -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, "^^ CLIENT READ ENDED, ENDING", err)
//debug.Println(client.id, "FINAL BUF", string(client.r.Get()))
// Publish last will and testament then close. // Publish last will and testament then close.
s.closeClient(client, sendLWT) s.closeClient(client, sendLWT)

View File

@@ -8,5 +8,5 @@ type Controller interface {
Authenticate(user, password []byte) bool Authenticate(user, password []byte) bool
// ACL returns true if a user has read or write access to a given topic. // 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
} }

View File

@@ -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. // ACL returns true if a user has access permissions to read or write on a topic.
// Allow always returns true. // 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 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. // ACL returns true if a user has access permissions to read or write on a topic.
// Disallow always returns false. // 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 return false
} }

View File

@@ -8,48 +8,48 @@ import (
func TestAllowAuth(t *testing.T) { func TestAllowAuth(t *testing.T) {
ac := new(Allow) 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) { func BenchmarkAllowAuth(b *testing.B) {
ac := new(Allow) ac := new(Allow)
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
ac.Authenticate("user", "pass") ac.Authenticate([]byte("user"), []byte("pass"))
} }
} }
func TestAllowACL(t *testing.T) { func TestAllowACL(t *testing.T) {
ac := new(Allow) 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) { func BenchmarkAllowACL(b *testing.B) {
ac := new(Allow) ac := new(Allow)
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
ac.ACL("user", "pass", true) ac.ACL([]byte("user"), "pass", true)
} }
} }
func TestDisallowAuth(t *testing.T) { func TestDisallowAuth(t *testing.T) {
ac := new(Disallow) 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) { func BenchmarkDisallowAuth(b *testing.B) {
ac := new(Disallow) ac := new(Disallow)
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
ac.Authenticate("user", "pass") ac.Authenticate([]byte("user"), []byte("pass"))
} }
} }
func TestDisallowACL(t *testing.T) { func TestDisallowACL(t *testing.T) {
ac := new(Disallow) 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) { func BenchmarkDisallowACL(b *testing.B) {
ac := new(Disallow) ac := new(Disallow)
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
ac.ACL("user", "pass", true) ac.ACL([]byte("user"), "pass", true)
} }
} }

View File

@@ -1,7 +1,6 @@
package mqtt package mqtt
import ( import (
"bytes"
"errors" "errors"
"net" "net"
@@ -150,7 +149,7 @@ func (s *Server) EstablishConnection(lid string, c net.Conn, ac auth.Controller)
retcode = packets.CodeConnectNotAuthorised 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 var sessionPresent bool
if existing, ok := s.Clients.Get(pk.ClientIdentifier); ok { 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) s.Clients.Add(client)
// Send a CONNACK back to the client. // Send a CONNACK back to the client.
/*err = s.writeClient(client, &packets.ConnackPacket{ err = s.writeClient(client, &packets.Packet{
FixedHeader: packets.FixedHeader{ FixedHeader: packets.FixedHeader{
Type: packets.Connack, Type: packets.Connack,
}, },
@@ -182,7 +181,6 @@ func (s *Server) EstablishConnection(lid string, c net.Conn, ac auth.Controller)
if err != nil { if err != nil {
return err return err
} }
*/
if retcode != packets.Accepted { if retcode != packets.Accepted {
return nil 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. // 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) _, err := cl.WritePacket(pk)
if err != nil { if err != nil {
return err return err