]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/sp.go
Sequential MTH optimization
[nncp.git] / src / sp.go
index 7e74823e93fdb8bb4094f227ff82134fa094d55d..1bb8f75d6e628b4b294f0b931dbdaf6d7af6b33c 100644 (file)
--- a/src/sp.go
+++ b/src/sp.go
@@ -41,14 +41,14 @@ const (
 )
 
 type MTHAndOffset struct {
-       mth    *MTH
+       mth    MTH
        offset uint64
 }
 
 type SPCheckerTask struct {
        nodeId *NodeId
        hsh    *[MTHSize]byte
-       mth    *MTH
+       mth    MTH
        done   chan []byte
 }
 
@@ -658,6 +658,17 @@ func (state *SPState) StartWorkers(
        }
        if !state.NoCK {
                spCheckerOnce.Do(func() { go SPChecker(state.Ctx) })
+               go func() {
+                       for job := range state.Ctx.JobsNoCK(state.Node.Id) {
+                               if job.PktEnc.Nice <= state.Nice {
+                                       spCheckerTasks <- SPCheckerTask{
+                                               nodeId: state.Node.Id,
+                                               hsh:    job.HshValue,
+                                               done:   state.payloads,
+                                       }
+                               }
+                       }
+               }()
        }
 
        // Remaining handshake payload sending
@@ -1428,7 +1439,7 @@ func (state *SPState) ProcessSP(payload []byte) ([][]byte, error) {
                        }
                        if hasherAndOffset != nil {
                                delete(state.fileHashers, filePath)
-                               if hasherAndOffset.mth.PrependSize == 0 {
+                               if hasherAndOffset.mth.PrependSize() == 0 {
                                        if bytes.Compare(hasherAndOffset.mth.Sum(nil), file.Hash[:]) != 0 {
                                                state.Ctx.LogE(
                                                        "sp-file-bad-checksum", lesp,