github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/firewall/incoming_firewall_noop.go (about)

     1  /*
     2   * Copyright (C) 2019 The "MysteriumNetwork/node" Authors.
     3   *
     4   * This program is free software: you can redistribute it and/or modify
     5   * it under the terms of the GNU General Public License as published by
     6   * the Free Software Foundation, either version 3 of the License, or
     7   * (at your option) any later version.
     8   *
     9   * This program is distributed in the hope that it will be useful,
    10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12   * GNU General Public License for more details.
    13   *
    14   * You should have received a copy of the GNU General Public License
    15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16   */
    17  
    18  package firewall
    19  
    20  import (
    21  	"net"
    22  
    23  	"github.com/rs/zerolog/log"
    24  )
    25  
    26  // incomingFirewallNoop is a implementation which only logs allow requests with no effects.
    27  // Used by default.
    28  type incomingFirewallNoop struct{}
    29  
    30  // Setup noop setup (just log call).
    31  func (ifn *incomingFirewallNoop) Setup() error {
    32  	log.Info().Msg("Rules bootstrap was requested")
    33  	return nil
    34  }
    35  
    36  // Teardown noop cleanup (just log call).
    37  func (ifn *incomingFirewallNoop) Teardown() {
    38  	log.Info().Msg("Rules reset was requested")
    39  }
    40  
    41  // BlockOutgoingTraffic just logs the call.
    42  func (ifn *incomingFirewallNoop) BlockIncomingTraffic(network net.IPNet) (IncomingRuleRemove, error) {
    43  	log.Info().Msg("Incoming traffic block requested")
    44  	return func() error {
    45  		log.Info().Msg("Incoming traffic block removed")
    46  		return nil
    47  	}, nil
    48  }
    49  
    50  // AllowIPAccess logs URL for which access was requested.
    51  func (ifn *incomingFirewallNoop) AllowURLAccess(rawURLs ...string) (IncomingRuleRemove, error) {
    52  	for _, rawURL := range rawURLs {
    53  		log.Info().Msgf("Allow URL %s access", rawURL)
    54  	}
    55  	return func() error {
    56  		for _, rawURL := range rawURLs {
    57  			log.Debug().Msgf("Rule for URL: %s removed", rawURL)
    58  		}
    59  		return nil
    60  	}, nil
    61  }
    62  
    63  // AllowIPAccess logs IP for which access was requested.
    64  func (ifn *incomingFirewallNoop) AllowIPAccess(ip net.IP) (IncomingRuleRemove, error) {
    65  	log.Info().Msg("Allow IP access")
    66  	return func() error {
    67  		log.Info().Msg("Rule for IP removed")
    68  		return nil
    69  	}, nil
    70  }
    71  
    72  var _ IncomingTrafficFirewall = &incomingFirewallNoop{}