2018-08-13 07:48:32 +00:00
|
|
|
package cassandra
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/binary"
|
|
|
|
|
2018-08-15 07:17:18 +00:00
|
|
|
osm "git.loafle.net/overflow/service_matcher-go"
|
2018-08-13 07:48:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type cassandra struct {
|
|
|
|
Version uint8
|
|
|
|
Flags uint8
|
|
|
|
Stream uint16
|
|
|
|
Opcode uint8
|
|
|
|
Length uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
type CassandraMatcher struct {
|
2018-08-15 07:17:18 +00:00
|
|
|
osm.Matchers
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *CassandraMatcher) Key() string {
|
|
|
|
return "CASSANDRA"
|
|
|
|
}
|
|
|
|
|
2018-09-12 04:26:27 +00:00
|
|
|
func (m *CassandraMatcher) Type() string {
|
|
|
|
return "NOSQL"
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *CassandraMatcher) Name(matchCtx *osm.MatchCtx) string {
|
2018-08-13 07:48:32 +00:00
|
|
|
return "Cassandra"
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:41:28 +00:00
|
|
|
func (m *CassandraMatcher) IsPrePacket() bool {
|
2018-08-13 07:48:32 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *CassandraMatcher) HasResponse(matchCtx *osm.MatchCtx, index int) bool {
|
2018-08-13 07:48:32 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *CassandraMatcher) IsError(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) bool {
|
2018-08-13 07:48:32 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *CassandraMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) error {
|
2018-08-13 07:48:32 +00:00
|
|
|
|
2018-09-03 06:42:56 +00:00
|
|
|
if packet == nil || !packet.Valid() {
|
2018-08-15 07:17:18 +00:00
|
|
|
return osm.NoPacketReceivedError()
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reader := new(bytes.Buffer)
|
2018-09-03 07:23:25 +00:00
|
|
|
reader.Write(packet.Buffer)
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
c := cassandra{}
|
|
|
|
if err := binary.Read(reader, binary.BigEndian, &c); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if c.Version != 0x84 {
|
2018-08-15 07:17:18 +00:00
|
|
|
return osm.NotMatchedError()
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
if c.Flags != 0x00 {
|
2018-08-15 07:17:18 +00:00
|
|
|
return osm.NotMatchedError()
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
if c.Stream != 0x00 {
|
2018-08-15 07:17:18 +00:00
|
|
|
return osm.NotMatchedError()
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
if c.Opcode != 0x06 {
|
2018-08-15 07:17:18 +00:00
|
|
|
return osm.NotMatchedError()
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-08-15 07:17:18 +00:00
|
|
|
func NewMatcher() osm.Matcher {
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
m := &CassandraMatcher{}
|
|
|
|
c := cassandra{
|
|
|
|
Version: 4,
|
|
|
|
Flags: 0,
|
|
|
|
Stream: 0,
|
|
|
|
Opcode: 5,
|
|
|
|
Length: 0,
|
|
|
|
}
|
|
|
|
writer := new(bytes.Buffer)
|
|
|
|
binary.Write(writer, binary.LittleEndian, c)
|
|
|
|
|
2018-08-15 07:17:18 +00:00
|
|
|
m.AddPacket(osm.NewPacket(writer.Bytes(), writer.Len()))
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|