I would like the responses to consider the older, less able body citizen ... young bucks seem to possess super powers I don't.
Bear spray.
Much easier to use than a pistol; generally does not have any legal fallout or, "You what?! You shot my dog!!!". A shotgun is a great option; however, is not "practical" in many surroundings (think the 'burbs, urban, neighborhoods...)
In my lifetime I have been bitten thrice, attacked more than that, and advanced upon many times by dogs; not to mention my "encounters" with the bear, the moose and once upon a time (and in another place) the mountain lion.
I have intervened twice this spring, getting between dogs chasing a teenage girl and an elderly couple out for a walk; both times I stopped while driving down a paved road and jumped out to assist. All three were very afraid and felt certain that the dogs were going to attack/bite them. Same dogs on both occasions. Tracked down the owners who had no idea their precious little pets were chasing people a mile from their home. Pack mentality; and it only takes two to start a pack. (Since that time I have heard that they walk them on leash and do not allow them to run free.)
When I lived in the bush, it was common practice to shoot loose dogs on sight; this in a village with sled dogs, but also the year's meat/fish drying/stored outside not to forget the children who also played outside.
I have seen firsthand the effects of: bear spray, harsh words, big sticks, and the application of hot lead. Cloud of bear spray turns 'em away. Not always so with the other options that I have witnessed. I was shocked by just how many rounds some dogs can "absorb" and keep coming when I witnessed a defensive shooting in a dog attack firsthand.
Dogs can be very territorial. And some have BIG territories.
First, be prepared to STOP the aggression. I hike daily and always carry bear spray; then again I live where there are big bears, and moose, and wolves, and dogs... and I see them all the time. I also carry a 10mm auto and often a 300 H&H magnum or 12 gauge shotgun; after all, it is always hunting season where I live, different game sometimes but always hunting season.
Second, SOLVE the problem. If you are seeing the same dogs "out and about", and especially if they are being aggressive, find out where they are coming from and either (or both) contact the owners and "Animal Control". If they don't take care of it, you may have to.
PS I have been around dogs all of my life, currently have three; none of them runs around loose/unattended. And for what it is worth, my folks do let their dogs run free, and have had them "bring back"/as in right on their tails bears and mountain lions just about to their front door; sometimes requiring a trip to the vets for some stitches for the dogs. (Not near where I live, but many many many miles south.)