Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Dec 10, 2024
2 parents af75a86 + 87274fe commit b47da38
Show file tree
Hide file tree
Showing 44 changed files with 757 additions and 586 deletions.
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@

<!-- ... -->

## v1.7.7~
## v1.7.8~

*??? ??, ????*

<!-- ... -->

## v1.7.7

*December 11, 2024*

### IMPROVEMENTS

- `pkg/anonymity`: move from pkg/network/anonymity -> pkg/anonymity
- `pkg/anonymity`: replace network.INode -> adapters.IAdapter

<!-- ... -->

## v1.7.6

*November 25, 2024*

### IMPROVEMENTS

- Update `pkg/network/anonymity/queue`: add GetConsumersCap
- `pkg/network/anonymity/queue`: add GetConsumersCap

### CHANGES

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<a href="https://vk.me/join/6Px6b0Qh/uZIK4ixUYWQm4Krepzq5xbYjYw=">
<img src="https://img.shields.io/badge/вконтакте-%232E87FB.svg?&style=for-the-badge&logo=vk&logoColor=white" alt="VKontakte" />
</a>
<a href="https://t.me/+9Kcxr8NyeU8zZDZi">
<img src="https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white" alt="Telegram" />
</a>
</p>
About project
</h2>
Expand Down
2 changes: 1 addition & 1 deletion build/build.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package build

const CVersion = "v1.7.6"
const CVersion = "v1.7.7"
File renamed without changes.
36 changes: 36 additions & 0 deletions pkg/anonymity/adapters/adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package adapters

import (
"context"

net_message "github.com/number571/go-peer/pkg/network/message"
)

var (
_ IAdapter = &sAdapter{}
)

type (
iProducerF func(context.Context, net_message.IMessage) error
iConsumerF func(context.Context) (net_message.IMessage, error)
)

type sAdapter struct {
fProduce iProducerF
fConsume iConsumerF
}

func NewAdapterByFuncs(pProduce iProducerF, pConsume iConsumerF) IAdapter {
return &sAdapter{
fProduce: pProduce,
fConsume: pConsume,
}
}

func (p *sAdapter) Produce(pCtx context.Context, pMsg net_message.IMessage) error {
return p.fProduce(pCtx, pMsg)
}

func (p *sAdapter) Consume(pCtx context.Context) (net_message.IMessage, error) {
return p.fConsume(pCtx)
}
50 changes: 50 additions & 0 deletions pkg/anonymity/adapters/adapters_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package adapters

import (
"bytes"
"context"
"testing"

"github.com/number571/go-peer/pkg/network/message"
"github.com/number571/go-peer/pkg/payload"
)

const (
tcMessage = "hello, world!"
)

func TestAdapter(t *testing.T) {
msgChan := make(chan message.IMessage, 1)
adapter := NewAdapterByFuncs(
func(_ context.Context, msg message.IMessage) error {
msgChan <- msg
return nil
},
func(_ context.Context) (message.IMessage, error) {
return <-msgChan, nil
},
)

ctx := context.Background()

err := adapter.Produce(ctx, message.NewMessage(
message.NewConstructSettings(&message.SConstructSettings{
FSettings: message.NewSettings(&message.SSettings{}),
}),
payload.NewPayload32(0x01, []byte(tcMessage)),
))
if err != nil {
t.Error(err)
return
}

msg, err := adapter.Consume(ctx)
if err != nil {
t.Error(err)
return
}
if !bytes.Equal(msg.GetPayload().GetBody(), []byte(tcMessage)) {
t.Error("consume invalid message")
return
}
}
20 changes: 20 additions & 0 deletions pkg/anonymity/adapters/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package adapters

import (
"context"

net_message "github.com/number571/go-peer/pkg/network/message"
)

type IAdapter interface {
IProducer
IConsumer
}

type IProducer interface {
Produce(context.Context, net_message.IMessage) error
}

type IConsumer interface {
Consume(context.Context) (net_message.IMessage, error)
}
Loading

0 comments on commit b47da38

Please sign in to comment.