mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-16 04:24:56 +02:00
rename transport to api
This commit is contained in:
parent
044ed4e891
commit
102045e47e
15 changed files with 40 additions and 40 deletions
|
|
@ -1,4 +1,4 @@
|
|||
package transport
|
||||
package api
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package transport
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package transport
|
||||
package api
|
||||
|
||||
// Reader interface defines the required method
|
||||
// to read a message from an channel.
|
||||
|
|
@ -3,7 +3,7 @@ package redis_common
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"thalos/transport"
|
||||
"thalos/api"
|
||||
)
|
||||
|
||||
// Key consists of a namespace and a channel.
|
||||
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
type Key struct {
|
||||
NS Namespace
|
||||
Channel transport.Channel
|
||||
Channel api.Channel
|
||||
}
|
||||
|
||||
func (k Key) String() string {
|
||||
|
|
@ -3,23 +3,23 @@ package redis_common
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"thalos/transport"
|
||||
"thalos/api"
|
||||
)
|
||||
|
||||
func TestKey_String(t *testing.T) {
|
||||
type fields struct {
|
||||
NS Namespace
|
||||
Channel transport.Channel
|
||||
Channel api.Channel
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
want string
|
||||
}{
|
||||
{"Empty", fields{NS: Namespace{}, Channel: transport.Channel{}}, "ship::0000000000000000000000000000000000000000000000000000000000000000::"},
|
||||
{"Transactions", fields{NS: Namespace{ChainID: "id"}, Channel: transport.Channel{"transactions"}}, "ship::id::transactions"},
|
||||
{"Nested", fields{NS: Namespace{ChainID: "id"}, Channel: transport.Channel{"one.two"}}, "ship::id::one.two"},
|
||||
{"Action", fields{NS: Namespace{ChainID: "id"}, Channel: transport.Action{Contract: "mycontract"}.Channel()}, "ship::id::actions/contract/mycontract"},
|
||||
{"Empty", fields{NS: Namespace{}, Channel: api.Channel{}}, "ship::0000000000000000000000000000000000000000000000000000000000000000::"},
|
||||
{"Transactions", fields{NS: Namespace{ChainID: "id"}, Channel: api.Channel{"transactions"}}, "ship::id::transactions"},
|
||||
{"Nested", fields{NS: Namespace{ChainID: "id"}, Channel: api.Channel{"one.two"}}, "ship::id::one.two"},
|
||||
{"Action", fields{NS: Namespace{ChainID: "id"}, Channel: api.Action{Contract: "mycontract"}.Channel()}, "ship::id::actions/contract/mycontract"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
@ -3,7 +3,7 @@ package redis_common
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"thalos/transport"
|
||||
"thalos/api"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -27,7 +27,7 @@ type Namespace struct {
|
|||
}
|
||||
|
||||
// Create a new key with this namespace.
|
||||
func (ns Namespace) NewKey(ch transport.Channel) Key {
|
||||
func (ns Namespace) NewKey(ch api.Channel) Key {
|
||||
return Key{NS: ns, Channel: ch}
|
||||
}
|
||||
|
||||
|
|
@ -3,8 +3,8 @@ package redis_pubsub
|
|||
import (
|
||||
"context"
|
||||
|
||||
"thalos/transport"
|
||||
. "thalos/transport/redis_common"
|
||||
"thalos/api"
|
||||
. "thalos/api/redis_common"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
|
@ -23,7 +23,7 @@ func NewPublisher(client *redis.Client, ns Namespace) *Publisher {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Publisher) Write(channel transport.Channel, payload []byte) error {
|
||||
func (r *Publisher) Write(channel api.Channel, payload []byte) error {
|
||||
return r.pipeline.Publish(r.ctx, r.ns.NewKey(channel).String(), payload).Err()
|
||||
}
|
||||
|
||||
|
|
@ -3,8 +3,8 @@ package redis_pubsub
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"thalos/transport"
|
||||
. "thalos/transport/redis_common"
|
||||
"thalos/api"
|
||||
. "thalos/api/redis_common"
|
||||
|
||||
"github.com/go-redis/redismock/v8"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -19,8 +19,8 @@ func TestPublisher_Write(t *testing.T) {
|
|||
mock.ExpectPublish("ship::id::test", []byte("some string")).SetVal(0)
|
||||
mock.ExpectPublish("ship::id::test2", []byte("some other string")).SetVal(0)
|
||||
|
||||
assert.NoError(t, pub.Write(transport.Channel{"test"}, []byte("some string")))
|
||||
assert.NoError(t, pub.Write(transport.Channel{"test2"}, []byte("some other string")))
|
||||
assert.NoError(t, pub.Write(api.Channel{"test"}, []byte("some string")))
|
||||
assert.NoError(t, pub.Write(api.Channel{"test2"}, []byte("some other string")))
|
||||
assert.NoError(t, pub.Flush())
|
||||
|
||||
assert.NoError(t, mock.ExpectationsWereMet())
|
||||
|
|
@ -5,8 +5,8 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"thalos/transport"
|
||||
. "thalos/transport/redis_common"
|
||||
"thalos/api"
|
||||
. "thalos/api/redis_common"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
|
@ -71,7 +71,7 @@ func (s *Subscriber) worker() {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Subscriber) Read(channel transport.Channel) ([]byte, error) {
|
||||
func (s *Subscriber) Read(channel api.Channel) ([]byte, error) {
|
||||
var err error
|
||||
|
||||
key := s.ns.NewKey(channel).String()
|
||||
|
|
@ -4,8 +4,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"thalos/transport"
|
||||
. "thalos/transport/redis_common"
|
||||
"thalos/api"
|
||||
. "thalos/api/redis_common"
|
||||
|
||||
"github.com/alicebob/miniredis/v2"
|
||||
"github.com/go-redis/redis/v8"
|
||||
|
|
@ -50,7 +50,7 @@ func TestSubscriber_Read(t *testing.T) {
|
|||
|
||||
// Redis pubsub does not guarentee that messages are sent in the correct order.
|
||||
for range expectedMessages {
|
||||
msg, err := s.Read(transport.Channel{"test"})
|
||||
msg, err := s.Read(api.Channel{"test"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Contains(t, expectedMessages, string(msg))
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package transport
|
||||
package api
|
||||
|
||||
// Writer interface defines the required methods
|
||||
// to send messages over an channel.
|
||||
|
|
@ -5,8 +5,8 @@ import (
|
|||
"encoding/json"
|
||||
|
||||
"thalos/abi"
|
||||
"thalos/transport"
|
||||
"thalos/transport/message"
|
||||
"thalos/api"
|
||||
"thalos/api/message"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
|
|
@ -29,12 +29,12 @@ func logDecoratedEncoder(encoder message.Encoder) message.Encoder {
|
|||
|
||||
type ShipProcessor struct {
|
||||
abi *abi.AbiManager
|
||||
writer transport.Writer
|
||||
writer api.Writer
|
||||
shipStream *shipclient.Stream
|
||||
encode message.Encoder
|
||||
}
|
||||
|
||||
func SpawnProccessor(shipStream *shipclient.Stream, writer transport.Writer, abi *abi.AbiManager) *ShipProcessor {
|
||||
func SpawnProccessor(shipStream *shipclient.Stream, writer api.Writer, abi *abi.AbiManager) *ShipProcessor {
|
||||
processor := &ShipProcessor{
|
||||
abi: abi,
|
||||
writer: writer,
|
||||
|
|
@ -49,7 +49,7 @@ func SpawnProccessor(shipStream *shipclient.Stream, writer transport.Writer, abi
|
|||
return processor
|
||||
}
|
||||
|
||||
func (processor *ShipProcessor) queueMessage(channel transport.Channel, payload []byte) bool {
|
||||
func (processor *ShipProcessor) queueMessage(channel api.Channel, payload []byte) bool {
|
||||
err := processor.writer.Write(channel, payload)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("Failed to post to channel '%s'", channel)
|
||||
|
|
@ -58,7 +58,7 @@ func (processor *ShipProcessor) queueMessage(channel transport.Channel, payload
|
|||
return true
|
||||
}
|
||||
|
||||
func (processor *ShipProcessor) encodeQueue(channel transport.Channel, v interface{}) bool {
|
||||
func (processor *ShipProcessor) encodeQueue(channel api.Channel, v interface{}) bool {
|
||||
if payload, err := processor.encode(v); err == nil {
|
||||
return processor.queueMessage(channel, payload)
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ func (processor *ShipProcessor) processBlock(block *ship.GetBlocksResultV0) {
|
|||
HeadBlockNum: block.Head.BlockNum,
|
||||
}
|
||||
|
||||
processor.encodeQueue(transport.HeartbeatChannel, hb)
|
||||
processor.encodeQueue(api.HeartbeatChannel, hb)
|
||||
|
||||
err := processor.writer.Flush()
|
||||
if err != nil {
|
||||
|
|
@ -89,7 +89,7 @@ func (processor *ShipProcessor) processBlock(block *ship.GetBlocksResultV0) {
|
|||
func (processor *ShipProcessor) processTraces(traces []*ship.TransactionTraceV0) {
|
||||
for _, trace := range traces {
|
||||
|
||||
processor.encodeQueue(transport.TransactionChannel, trace)
|
||||
processor.encodeQueue(api.TransactionChannel, trace)
|
||||
|
||||
// Actions
|
||||
for _, actionTraceVar := range trace.ActionTraces {
|
||||
|
|
@ -139,11 +139,11 @@ func (processor *ShipProcessor) processTraces(traces []*ship.TransactionTraceV0)
|
|||
continue
|
||||
}
|
||||
|
||||
channels := []transport.Channel{
|
||||
transport.Action{}.Channel(),
|
||||
transport.Action{Name: act.Name}.Channel(),
|
||||
transport.Action{Contract: act.Contract}.Channel(),
|
||||
transport.Action{Name: act.Name, Contract: act.Contract}.Channel(),
|
||||
channels := []api.Channel{
|
||||
api.Action{}.Channel(),
|
||||
api.Action{Name: act.Name}.Channel(),
|
||||
api.Action{Contract: act.Contract}.Channel(),
|
||||
api.Action{Name: act.Name, Contract: act.Contract}.Channel(),
|
||||
}
|
||||
|
||||
for _, channel := range channels {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue