// This function is called from the main thread (or from an UI) func NetRouteInvExt(typ uint32, h *btc.Uint256, fromConn *OneConnection, fee_spkb uint64) (cnt uint) { common.CountSafe(fmt.Sprint("NetRouteInv", typ)) // Prepare the inv inv := new([36]byte) binary.LittleEndian.PutUint32(inv[0:4], typ) copy(inv[4:36], h.Bytes()) // Append it to PendingInvs in each open connection Mutex_net.Lock() for _, v := range OpenCons { if v != fromConn { // except the one that this inv came from send_inv := true v.Mutex.Lock() if typ == MSG_TX { if v.Node.DoNotRelayTxs { send_inv = false common.CountSafe("SendInvNoTxNode") } else if v.X.MinFeeSPKB > 0 && uint64(v.X.MinFeeSPKB) > fee_spkb { send_inv = false common.CountSafe("SendInvFeeTooLow") } /* This is to prevent sending own txs to "spying" peers: else if fromConn==nil && v.X.InvsRecieved==0 { send_inv = false common.CountSafe("SendInvOwnBlocked") } */ } if send_inv { if len(v.PendingInvs) < 500 { if typ, ok := v.InvDone.Map[hash2invid(inv[4:36])]; ok { common.CountSafe(fmt.Sprint("SendInvSame-", typ)) } else { v.PendingInvs = append(v.PendingInvs, inv) cnt++ } } else { common.CountSafe("SendInvFull") } } v.Mutex.Unlock() } } Mutex_net.Unlock() return }
func SendInvToRandomPeer(typ uint32, h *btc.Uint256) { common.CountSafe(fmt.Sprint("NetSendOneInv", typ)) // Prepare the inv inv := new([36]byte) binary.LittleEndian.PutUint32(inv[0:4], typ) copy(inv[4:36], h.Bytes()) // Append it to PendingInvs in a random connection network.Mutex_net.Lock() idx := rand.Intn(len(network.OpenCons)) var cnt int for _, v := range network.OpenCons { if idx == cnt { v.Mutex.Lock() v.PendingInvs = append(v.PendingInvs, inv) v.Mutex.Unlock() break } cnt++ } network.Mutex_net.Unlock() return }
// This function is called from the main thread (or from an UI) func NetRouteInv(typ uint32, h *btc.Uint256, fromConn *OneConnection) (cnt uint) { common.CountSafe(fmt.Sprint("NetRouteInv", typ)) // Prepare the inv inv := new([36]byte) binary.LittleEndian.PutUint32(inv[0:4], typ) copy(inv[4:36], h.Bytes()) // Append it to PendingInvs in each open connection Mutex_net.Lock() for _, v := range OpenCons { if v != fromConn { // except the one that this inv came from v.Mutex.Lock() if v.Node.DoNotRelayTxs && typ == 1 { // This node does not want tx inv (it came with its version message) common.CountSafe("SendInvNoTxNode") } else { if fromConn == nil && v.InvsRecieved == 0 { // Do not broadcast own txs to nodes that never sent any invs to us common.CountSafe("SendInvOwnBlocked") } else if len(v.PendingInvs) < 500 { v.PendingInvs = append(v.PendingInvs, inv) cnt++ } else { common.CountSafe("SendInvIgnored") } } v.Mutex.Unlock() } } Mutex_net.Unlock() if cnt == 0 { NetAlerts <- "WARNING: your tx has not been broadcasted to any peer" } return }