<commit_before>// Copyright 2015 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.

// Glue code between BTCD code & Factom.

package btcd

import (
	"errors"
	"fmt"
	"os"

	//	"github.com/FactomProject/btcd/chaincfg"
	//	"github.com/FactomProject/btcutil"

	cp "github.com/FactomProject/FactomCode/controlpanel"
	"github.com/FactomProject/FactomCode/database"
	"github.com/FactomProject/btcd/wire"
	"github.com/davecgh/go-spew/spew"
)

var _ = fmt.Printf

var (
	local_Server *server
	db           database.Db              // database
	inMsgQueue   chan wire.FtmInternalMsg //incoming message queue for factom application messages
	outMsgQueue  chan wire.FtmInternalMsg //outgoing message queue for factom application messages

	inCtlMsgQueue  chan wire.FtmInternalMsg //incoming message queue for factom control messages
	outCtlMsgQueue chan wire.FtmInternalMsg //outgoing message queue for factom control messages
)

// start up Factom queue(s) managers/processors
// this is to be called within the btcd's main code
func factomForkInit(s *server) {
	// tweak some config options
	cfg.DisableCheckpoints = true

	local_Server = s // local copy of our server pointer

	// Write outgoing factom messages into P2P network
	go func() {
		for msg := range outMsgQueue {
			switch msg.(type) {
			case *wire.MsgInt_DirBlock:
				dirBlock, _ := msg.(*wire.MsgInt_DirBlock)
				iv := wire.NewInvVect(wire.InvTypeFactomDirBlock, dirBlock.ShaHash)
				s.RelayInventory(iv, nil)

			case wire.Message:
				wireMsg, _ := msg.(wire.Message)
				//s.BroadcastMessage(wireMsg)
				if ClientOnly {
					//fmt.Println("broadcasting from client.")
					s.BroadcastMessage(wireMsg)
				} else {
					if _, ok := msg.(*wire.MsgAcknowledgement); ok {
						//fmt.Println("broadcasting from server.")
						s.BroadcastMessage(wireMsg)
					}
				}

			case *wire.MsgInt_ReSyncup:
				msg, _ := msg.(*wire.MsgInt_ReSyncup)
				fmt.Println("MsgInt_ReSyncup: ", spew.Sdump(msg))
				p := local_Server.SyncPeer()
				if p != nil {
					fmt.Println("start re-syncup: ")
					locator := DirBlockLocatorFromHash(msg.StartHash)
					p.PushGetDirBlocksMsg(locator, msg.StopHash) //&zeroHash)
				}
				fmt.Println("sync peer is nil, no syncup renewed.")

			default:
				panic(fmt.Sprintf("bad outMsgQueue message received: %v", msg))
			}
		}
	}()

	go func() {
		for msg := range outCtlMsgQueue {

			fmt.Printf("in range outCtlMsgQueue, msg:%+v\n", msg)

			msgEom, _ := msg.(*wire.MsgInt_EOM)

			//			switch msgEom.Command() {
			switch msg.Command() {
<commit_msg>hack fix for re-sync<commit_after>// Copyright 2015 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.

// Glue code between BTCD code & Factom.

package btcd

import (
	"errors"
	"fmt"
	"os"

	//	"github.com/FactomProject/btcd/chaincfg"
	//	"github.com/FactomProject/btcutil"

	cp "github.com/FactomProject/FactomCode/controlpanel"
	"github.com/FactomProject/FactomCode/database"
	"github.com/FactomProject/btcd/wire"
	"github.com/davecgh/go-spew/spew"
)

var _ = fmt.Printf

var (
	local_Server *server
	db           database.Db              // database
	inMsgQueue   chan wire.FtmInternalMsg //incoming message queue for factom application messages
	outMsgQueue  chan wire.FtmInternalMsg //outgoing message queue for factom application messages

	inCtlMsgQueue  chan wire.FtmInternalMsg //incoming message queue for factom control messages
	outCtlMsgQueue chan wire.FtmInternalMsg //outgoing message queue for factom control messages
)

// start up Factom queue(s) managers/processors
// this is to be called within the btcd's main code
func factomForkInit(s *server) {
	// tweak some config options
	cfg.DisableCheckpoints = true

	local_Server = s // local copy of our server pointer

	// Write outgoing factom messages into P2P network
	go func() {
		for msg := range outMsgQueue {
			switch msg.(type) {
			case *wire.MsgInt_DirBlock:
				dirBlock, _ := msg.(*wire.MsgInt_DirBlock)
				iv := wire.NewInvVect(wire.InvTypeFactomDirBlock, dirBlock.ShaHash)
				s.RelayInventory(iv, nil)

			case wire.Message:
				wireMsg, _ := msg.(wire.Message)
				//s.BroadcastMessage(wireMsg)
				if ClientOnly {
					//fmt.Println("broadcasting from client.")
					s.BroadcastMessage(wireMsg)
				} else {
					if _, ok := msg.(*wire.MsgAcknowledgement); ok {
						//fmt.Println("broadcasting from server.")
						s.BroadcastMessage(wireMsg)
					}
				}

			case *wire.MsgInt_ReSyncup:
				msg, _ := msg.(*wire.MsgInt_ReSyncup)
				fmt.Println("MsgInt_ReSyncup: ", spew.Sdump(msg))
				p := local_Server.SyncPeer()
				if p != nil {
					fmt.Println("start re-syncup: ")
					locator := DirBlockLocatorFromHash(msg.StartHash)
					p.PushGetDirBlocksMsg(locator, &zeroHash)
				}
				fmt.Println("sync peer is nil, no syncup renewed.")

			default:
				panic(fmt.Sprintf("bad outMsgQueue message received: %v", msg))
			}
		}
	}()

	go func() {
		for msg := range outCtlMsgQueue {

			fmt.Printf("in range outCtlMsgQueue, msg:%+v\n", msg)

			msgEom, _ := msg.(*wire.MsgInt_EOM)

			//			switch msgEom.Command() {
			switch msg.Command() {

{'fraction_non_alphanumeric': 0.11303012857417002, 'fraction_numerical': 0.0019190174630589138, 'mean_word_length': 3.3253112033195023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4166904', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1738, 'n_words': 434}