Skip to content
Snippets Groups Projects
Commit 7fa48aa3 authored by Hans Moog's avatar Hans Moog
Browse files

Feat: started porting approvers to model package + fixed some issues

parent 83ec67d7
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,8 @@ package datastructure ...@@ -2,6 +2,8 @@ package datastructure
import ( import (
"sync" "sync"
"github.com/iotaledger/goshimmer/packages/typeutils"
) )
type lruCacheElement struct { type lruCacheElement struct {
...@@ -101,7 +103,7 @@ func (cache *LRUCache) ComputeIfPresent(key interface{}, callback func(value int ...@@ -101,7 +103,7 @@ func (cache *LRUCache) ComputeIfPresent(key interface{}, callback func(value int
if entry, exists := cache.directory[key]; exists { if entry, exists := cache.directory[key]; exists {
result = entry.GetValue().(*lruCacheElement).value result = entry.GetValue().(*lruCacheElement).value
if callbackResult := callback(result); result != nil { if callbackResult := callback(result); !typeutils.IsInterfaceNil(callbackResult) {
result = callbackResult result = callbackResult
cache.set(key, callbackResult) cache.set(key, callbackResult)
......
...@@ -3,7 +3,7 @@ package filter ...@@ -3,7 +3,7 @@ package filter
import ( import (
"sync" "sync"
"github.com/iotaledger/goshimmer/packages/typeconversion" "github.com/iotaledger/goshimmer/packages/typeutils"
) )
type ByteArrayFilter struct { type ByteArrayFilter struct {
...@@ -25,20 +25,20 @@ func (filter *ByteArrayFilter) Contains(byteArray []byte) bool { ...@@ -25,20 +25,20 @@ func (filter *ByteArrayFilter) Contains(byteArray []byte) bool {
filter.mutex.RLock() filter.mutex.RLock()
defer filter.mutex.RUnlock() defer filter.mutex.RUnlock()
_, exists := filter.byteArraysByKey[typeconversion.BytesToString(byteArray)] _, exists := filter.byteArraysByKey[typeutils.BytesToString(byteArray)]
return exists return exists
} }
func (filter *ByteArrayFilter) Add(byteArray []byte) bool { func (filter *ByteArrayFilter) Add(byteArray []byte) bool {
key := typeconversion.BytesToString(byteArray) key := typeutils.BytesToString(byteArray)
filter.mutex.Lock() filter.mutex.Lock()
defer filter.mutex.Unlock() defer filter.mutex.Unlock()
if _, exists := filter.byteArraysByKey[key]; !exists { if _, exists := filter.byteArraysByKey[key]; !exists {
if len(filter.byteArrays) == filter.size { if len(filter.byteArrays) == filter.size {
delete(filter.byteArraysByKey, typeconversion.BytesToString(filter.byteArrays[0])) delete(filter.byteArraysByKey, typeutils.BytesToString(filter.byteArrays[0]))
filter.byteArrays = append(filter.byteArrays[1:], byteArray) filter.byteArrays = append(filter.byteArrays[1:], byteArray)
} else { } else {
......
package approvers
import (
"sync"
"github.com/iotaledger/goshimmer/packages/ternary"
)
type Approvers struct {
hash ternary.Trinary
hashes map[ternary.Trinary]bool
hashesMutex sync.RWMutex
modified bool
}
func NewApprovers(hash ternary.Trinary) *Approvers {
return &Approvers{
hash: hash,
hashes: make(map[ternary.Trinary]bool),
modified: false,
}
}
package typeconversion package typeutils
import ( import (
"reflect" "reflect"
...@@ -16,3 +16,7 @@ func StringToBytes(str string) []byte { ...@@ -16,3 +16,7 @@ func StringToBytes(str string) []byte {
return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{Data: hdr.Data, Len: hdr.Len, Cap: hdr.Len})) return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{Data: hdr.Data, Len: hdr.Len, Cap: hdr.Len}))
} }
func IsInterfaceNil(param interface{}) bool {
return param == nil || (*[2]uintptr)(unsafe.Pointer(&param))[1] == 0
}
package gossip package gossip
import ( import (
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/model/meta_transaction"
"github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/node"
) )
...@@ -12,10 +10,6 @@ func configure(plugin *node.Plugin) { ...@@ -12,10 +10,6 @@ func configure(plugin *node.Plugin) {
configureNeighbors(plugin) configureNeighbors(plugin)
configureServer(plugin) configureServer(plugin)
configureSendQueue(plugin) configureSendQueue(plugin)
Events.ReceiveTransaction.Attach(events.NewClosure(func(tx *meta_transaction.MetaTransaction) {
plugin.LogDebug("Received TX " + string(tx.GetHash()))
}))
} }
func run(plugin *node.Plugin) { func run(plugin *node.Plugin) {
......
...@@ -150,7 +150,7 @@ var connectedNeighborsMutex sync.RWMutex ...@@ -150,7 +150,7 @@ var connectedNeighborsMutex sync.RWMutex
var sendQueue = make(chan *meta_transaction.MetaTransaction, SEND_QUEUE_SIZE) var sendQueue = make(chan *meta_transaction.MetaTransaction, SEND_QUEUE_SIZE)
const ( const (
SEND_QUEUE_SIZE = 500 SEND_QUEUE_SIZE = 50000
) )
// endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////// // endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/iotaledger/goshimmer/packages/datastructure" "github.com/iotaledger/goshimmer/packages/datastructure"
"github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/errors"
"github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/goshimmer/packages/ternary"
"github.com/iotaledger/goshimmer/packages/typeconversion" "github.com/iotaledger/goshimmer/packages/typeutils"
) )
// region global public api //////////////////////////////////////////////////////////////////////////////////////////// // region global public api ////////////////////////////////////////////////////////////////////////////////////////////
...@@ -132,13 +132,13 @@ func (approvers *Approvers) Unmarshal(data []byte) (err errors.IdentifiableError ...@@ -132,13 +132,13 @@ func (approvers *Approvers) Unmarshal(data []byte) (err errors.IdentifiableError
approvers.hashesMutex.Lock() approvers.hashesMutex.Lock()
approvers.hash = ternary.Trinary(typeconversion.BytesToString(data[MARSHALLED_APPROVERS_HASH_START:MARSHALLED_APPROVERS_HASH_END])) approvers.hash = ternary.Trinary(typeutils.BytesToString(data[MARSHALLED_APPROVERS_HASH_START:MARSHALLED_APPROVERS_HASH_END]))
approvers.hashes = make(map[ternary.Trinary]bool, hashesCount) approvers.hashes = make(map[ternary.Trinary]bool, hashesCount)
for i := uint64(0); i < hashesCount; i++ { for i := uint64(0); i < hashesCount; i++ {
var HASH_START = MARSHALLED_APPROVERS_HASHES_START + i*(MARSHALLED_APPROVERS_HASH_SIZE) var HASH_START = MARSHALLED_APPROVERS_HASHES_START + i*(MARSHALLED_APPROVERS_HASH_SIZE)
var HASH_END = HASH_START * MARSHALLED_APPROVERS_HASH_SIZE var HASH_END = HASH_START * MARSHALLED_APPROVERS_HASH_SIZE
approvers.hashes[ternary.Trinary(typeconversion.BytesToString(data[HASH_START:HASH_END]))] = true approvers.hashes[ternary.Trinary(typeutils.BytesToString(data[HASH_START:HASH_END]))] = true
} }
approvers.hashesMutex.Unlock() approvers.hashesMutex.Unlock()
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"github.com/iotaledger/goshimmer/packages/bitutils" "github.com/iotaledger/goshimmer/packages/bitutils"
"github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/errors"
"github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/goshimmer/packages/ternary"
"github.com/iotaledger/goshimmer/packages/typeconversion" "github.com/iotaledger/goshimmer/packages/typeutils"
) )
// region type definition and constructor ////////////////////////////////////////////////////////////////////////////// // region type definition and constructor //////////////////////////////////////////////////////////////////////////////
...@@ -228,7 +228,7 @@ func (metadata *TransactionMetadata) Unmarshal(data []byte) errors.IdentifiableE ...@@ -228,7 +228,7 @@ func (metadata *TransactionMetadata) Unmarshal(data []byte) errors.IdentifiableE
metadata.finalizedMutex.Lock() metadata.finalizedMutex.Lock()
defer metadata.finalizedMutex.Unlock() defer metadata.finalizedMutex.Unlock()
metadata.hash = ternary.Trinary(typeconversion.BytesToString(data[MARSHALLED_HASH_START:MARSHALLED_HASH_END])) metadata.hash = ternary.Trinary(typeutils.BytesToString(data[MARSHALLED_HASH_START:MARSHALLED_HASH_END]))
if err := metadata.receivedTime.UnmarshalBinary(data[MARSHALLED_RECEIVED_TIME_START:MARSHALLED_RECEIVED_TIME_END]); err != nil { if err := metadata.receivedTime.UnmarshalBinary(data[MARSHALLED_RECEIVED_TIME_START:MARSHALLED_RECEIVED_TIME_END]); err != nil {
return ErrUnmarshalFailed.Derive(err, "could not unmarshal the received time") return ErrUnmarshalFailed.Derive(err, "could not unmarshal the received time")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment