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

Fix: fixed a bug in autopeering

parent cd38ad02
No related branches found
No related tags found
No related merge requests found
...@@ -42,15 +42,33 @@ func BenchmarkEd25519(b *testing.B) { ...@@ -42,15 +42,33 @@ func BenchmarkEd25519(b *testing.B) {
wg.Wait() wg.Wait()
} }
func BenchmarkBlake2b(b *testing.B) { var sampleTransactionData = make([]byte, 750)
data := make([]byte, 750)
func BenchmarkBytesToTrits(b *testing.B) {
bytes := blake2b.Sum512(sampleTransactionData)
b.ResetTimer()
var wg sync.WaitGroup
for i := 0; i < b.N; i++ {
wg.Add(1)
go func() {
_, _ = trinary.BytesToTrits(bytes[:])
wg.Done()
}()
}
wg.Wait()
}
func BenchmarkBlake2b(b *testing.B) {
var wg sync.WaitGroup var wg sync.WaitGroup
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
wg.Add(1) wg.Add(1)
go func() { go func() {
blake2b.Sum256(data) blake2b.Sum256(sampleTransactionData)
wg.Done() wg.Done()
}() }()
......
...@@ -22,9 +22,11 @@ type Identity struct { ...@@ -22,9 +22,11 @@ type Identity struct {
func NewIdentity(publicKey []byte, optionalPrivateKey ...[]byte) *Identity { func NewIdentity(publicKey []byte, optionalPrivateKey ...[]byte) *Identity {
this := &Identity{ this := &Identity{
Identifier: crypto.Hash20(publicKey), Identifier: crypto.Hash20(publicKey),
PublicKey: publicKey, PublicKey: make([]byte, len(publicKey)),
} }
copy(this.PublicKey, publicKey)
this.StringIdentifier = fmt.Sprintf("%x", this.Identifier) this.StringIdentifier = fmt.Sprintf("%x", this.Identifier)
if len(optionalPrivateKey) == 1 { if len(optionalPrivateKey) == 1 {
......
package peer
import (
"net"
"testing"
"time"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/salt"
"github.com/iotaledger/goshimmer/packages/identity"
"github.com/magiconair/properties/assert"
)
func TestPeer_MarshalUnmarshal(t *testing.T) {
peer := &Peer{
Address: net.IPv4(127, 0, 0, 1),
Identity: identity.GenerateRandomIdentity(),
GossipPort: 123,
PeeringPort: 456,
Salt: salt.New(30 * time.Second),
}
restoredPeer, _ := Unmarshal(peer.Marshal())
assert.Equal(t, peer.Address, restoredPeer.Address)
assert.Equal(t, peer.Identity.StringIdentifier, restoredPeer.Identity.StringIdentifier)
assert.Equal(t, peer.Identity.PublicKey, restoredPeer.Identity.PublicKey)
assert.Equal(t, peer.GossipPort, restoredPeer.GossipPort)
assert.Equal(t, peer.PeeringPort, restoredPeer.PeeringPort)
assert.Equal(t, peer.Salt, restoredPeer.Salt)
}
package response
import (
"net"
"testing"
"time"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/peer"
"github.com/iotaledger/goshimmer/packages/identity"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/salt"
)
func TestPeer_MarshalUnmarshal(t *testing.T) {
issuer := &peer.Peer{
Address: net.IPv4(127, 0, 0, 1),
Identity: identity.GenerateRandomIdentity(),
GossipPort: 123,
PeeringPort: 456,
Salt: salt.New(30 * time.Second),
}
peers := make([]*peer.Peer, 0)
peers = append(peers, &peer.Peer{
Address: net.IPv4(127, 0, 0, 1),
Identity: identity.GenerateRandomIdentity(),
GossipPort: 124,
PeeringPort: 457,
Salt: salt.New(30 * time.Second),
}, &peer.Peer{
Address: net.IPv4(127, 0, 0, 1),
Identity: identity.GenerateRandomIdentity(),
GossipPort: 125,
PeeringPort: 458,
Salt: salt.New(30 * time.Second),
}, &peer.Peer{
Address: net.IPv4(127, 0, 0, 1),
Identity: identity.GenerateRandomIdentity(),
GossipPort: 126,
PeeringPort: 459,
Salt: salt.New(30 * time.Second),
})
response := &Response{
Issuer: issuer,
Type: TYPE_ACCEPT,
Peers: peers,
}
response.Sign()
_, err := Unmarshal(response.Marshal())
if err != nil {
t.Error(err)
}
}
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
var seed = client.NewSeed("YFHQWAUPCXC9S9DSHP9NDF9RLNPMZVCMSJKUKQP9SWUSUCPRQXCMDVDVZ9SHHESHIQNCXWBJF9UJSWE9Z", consts.SecurityLevelMedium) var seed = client.NewSeed("YFHQWAUPCXC9S9DSHP9NDF9RLNPMZVCMSJKUKQP9SWUSUCPRQXCMDVDVZ9SHHESHIQNCXWBJF9UJSWE9Z", consts.SecurityLevelMedium)
func Benchmark(b *testing.B) { func BenchmarkValidateSignatures(b *testing.B) {
bundleFactory := client.NewBundleFactory() bundleFactory := client.NewBundleFactory()
bundleFactory.AddInput(seed.GetAddress(0), -400) bundleFactory.AddInput(seed.GetAddress(0), -400)
bundleFactory.AddOutput(seed.GetAddress(1), 400, "Testmessage") bundleFactory.AddOutput(seed.GetAddress(1), 400, "Testmessage")
...@@ -54,11 +54,11 @@ func TestValidateSignatures(t *testing.T) { ...@@ -54,11 +54,11 @@ func TestValidateSignatures(t *testing.T) {
generatedBundle := bundleFactory.GenerateBundle(tipselection.GetRandomTip(), tipselection.GetRandomTip()) generatedBundle := bundleFactory.GenerateBundle(tipselection.GetRandomTip(), tipselection.GetRandomTip())
successfull, err := ValidateSignatures(generatedBundle.GetEssenceHash(), generatedBundle.GetTransactions()) successful, err := ValidateSignatures(generatedBundle.GetEssenceHash(), generatedBundle.GetTransactions())
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
assert.Equal(t, successfull, true, "validation failed") assert.Equal(t, successful, true, "validation failed")
} }
func TestProcessSolidBundleHead_Data(t *testing.T) { func TestProcessSolidBundleHead_Data(t *testing.T) {
......
...@@ -70,7 +70,7 @@ func ValidateSignatures(bundleHash trinary.Hash, txs []*value_transaction.ValueT ...@@ -70,7 +70,7 @@ func ValidateSignatures(bundleHash trinary.Hash, txs []*value_transaction.ValueT
} }
// validate all the fragments against the address using Kerl // validate all the fragments against the address using Kerl
valid, err := signing.ValidateSignatures(address, fragments, bundleHash, signing.NewKerl) valid, err := signing.ValidateSignatures(address, fragments, bundleHash)
if err != nil { if err != nil {
return false, err return false, err
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment