github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/firewall/outgoing_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  	"github.com/rs/zerolog/log"
    22  )
    23  
    24  // outgoingFirewallNoop is a Vendor implementation which only logs allow requests with no effects.
    25  // Used by default.
    26  type outgoingFirewallNoop struct{}
    27  
    28  // Setup noop setup (just log call).
    29  func (ofn *outgoingFirewallNoop) Setup() error {
    30  	return nil
    31  }
    32  
    33  // Teardown noop cleanup (just log call).
    34  func (ofn *outgoingFirewallNoop) Teardown() {
    35  	log.Info().Msg("Rules reset was requested")
    36  }
    37  
    38  // BlockOutgoingTraffic just logs the call.
    39  func (ofn *outgoingFirewallNoop) BlockOutgoingTraffic(scope Scope, outboundIP string) (OutgoingRuleRemove, error) {
    40  	log.Info().Msg("Outgoing traffic block requested")
    41  	return func() {
    42  		log.Info().Msg("Outgoing traffic block removed")
    43  	}, nil
    44  }
    45  
    46  // AllowIPAccess logs IP for which access was requested.
    47  func (ofn *outgoingFirewallNoop) AllowIPAccess(ip string) (OutgoingRuleRemove, error) {
    48  	log.Info().Msg("Allow IP access")
    49  	return func() {
    50  		log.Info().Msg("Rule for IP removed")
    51  	}, nil
    52  }
    53  
    54  // AllowIPAccess logs URL for which access was requested.
    55  func (ofn *outgoingFirewallNoop) AllowURLAccess(rawURLs ...string) (OutgoingRuleRemove, error) {
    56  	for _, rawURL := range rawURLs {
    57  		log.Info().Msgf("Allow URL %s access", rawURL)
    58  	}
    59  	return func() {
    60  		for _, rawURL := range rawURLs {
    61  			log.Debug().Msgf("Rule for URL: %s removed", rawURL)
    62  		}
    63  	}, nil
    64  }
    65  
    66  var _ OutgoingTrafficFirewall = &outgoingFirewallNoop{}